title: extjs - how correctly call a controller method from another controller or closure
body: <p>I'm new to extjs and I'm using the MVC architecture.</p>
  <p>When my application references a method of a controller, I do it that way (in <code>MyApp.Application</code>):</p>
  <pre><code>Mb.app.getController('Main').myMethod();
  </code></pre>
  <p>It is already long, but I think this is the way to do.</p>
  <p>When a controller calls it's own method in a closure, I was led to use this code (in <code>MyApp.controller.Main</code>:</p>
  <pre><code>controllerMethodOne: function(){
      Ext.Ajax.request({
          url: ...,
          params: ...,
          success: (function(response){
              list = Ext.JSON.decode(response.responseText);
              list.forEach(function(item){
                  storeMenu.add(
                      Ext.create('Ext.menu.Item', {
                          text: item.text,
                          handler: function(el){MyApp.app.getController('Main').controllerMethodTwo()}
                      })
                  )
              })
          })
      })
  },
  </code></pre>
  <p>I referenced the method with <code>MyApp.app.getController('Main').controllerMethodTwo()</code> because <code>this</code> is not refering to the controller object in the closure, and thus <code>this..controllerMethodTwo()</code>isn't working.</p>
  <p>I find this utterly convoluted, and I hope someone has an idea to get around that <code>MyApp.app.getController</code>-workaround.</p>
  <h2>Update</h2>
  <p>Thanks to all the suggestion I could optimize my code and came up with:</p>
  <pre><code>// in my controller
      mixins: ['Mb.controller.mixin.StoreMenu'],
      // I use that style of menus in two controllers thats why I use a mixin
      init: function() {
          this.control({
              '#vg_storeMenu menuitem': {
                  click: this.onStoreMenuClicked
              }
          })
      },
  
  // the controller mixin
  Ext.define('Mb.controller.mixin.StoreMenu', {
      extend: 'Ext.app.Controller',
      buildStoreMenu: function(store_name){
          var storeMenu = Ext.ComponentQuery.query('#' + store_name + 'Menu')[0];
          Ext.Ajax.request({
              url: Paths.ajax + 'json.php',
              params: {list: store_name + 's'},
              success: (function(response){
              list = Ext.JSON.decode(response.responseText);
              items = Ext.Array.map(list, function(item) {
                  return {
                      xtype: 'menuitem',
                      text: item.text
                  }
              });
                  storeMenu.add(items);
              })
          })
      },
      onStoreMenuClicked: function(el){
          ...
      }
  });
  </code></pre>