Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have found a work around for this problem. It isn't as direct as one may hope, but it leaves all of your "action" code in the controller. </p> <p><strong>requirment</strong>: Wrap the html section of your page in an actual <code>Ext.Component</code>. This will likely be the case either way. So for instance, you may have a simple view that contains your HTML as follows:</p> <pre><code>Ext.define('app.view.myView', { extend: 'Ext.panel.Panel', alias: 'widget.myView', title: 'My Cool Panel', html: '&lt;div&gt;&lt;a href="#"&gt;This link will open a window&lt;/a&gt;&lt;/div&gt;&lt;br /&gt; &lt;label for="myInput"&gt;Type here: &lt;/label&gt;&lt;input name="myInput" type="text" value="" /&gt;', initComponent: function(){ var me = this; me.callParent(arguments); } }); </code></pre> <p>Then in the controller you use the <code>afterrender</code> event to apply listeners to your DOM elements. In the example below I illustrate both links (a element) and input elements:</p> <pre><code>Ext.define('app.controller.myController', { extend: 'Ext.app.Controller', init: function() { this.control({ 'myView': { afterrender: function(cmp){ var me = this; //the controller var inputs = cmp.getEl().select('input'); // will grab all DOM inputs inputs.on('keyup', function(evt, el, o){ me.testFunction(el); //you can call a function here }); var links = cmp.getEl().select('a'); //will grab all DOM a elements (links) links.on('click', function(evt, el, o){ //or you can write your code inline here Ext.Msg.show({ title: 'OMG!', msg: 'The controller handled the "a" element! OMG!' }); }); } } }); }, testFunction: function(el) { var str = 'You typed ' + el.value; Ext.Msg.show({ title: 'WOW!', msg: str }); } }); </code></pre> <p>And there you have it, DOM elements handled within the controller and adhering to the MVC architecture! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload