javascript - EXTJS5 MVVM: Get global controller from view controller - Stack Overflow

From a global controller, I can easily get a reference to another global controller with this.getContro

From a global controller, I can easily get a reference to another global controller with

this.getController('TargetController');

However, within the context of a view controller, how can I get a reference to that same controller? i.e.:

Ext.define('myCoolApp.view.SomeNeatController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.someneat',

    // this is bound to a button click event, let's say.
    onClick: function(button) {

        // How to get a reference to a global controller here? 
        // this.getController('TargetController'); is not defined
        // on the view controller....

    }

});

Probably something simple I'm missing, but any help would be appreciated.

From a global controller, I can easily get a reference to another global controller with

this.getController('TargetController');

However, within the context of a view controller, how can I get a reference to that same controller? i.e.:

Ext.define('myCoolApp.view.SomeNeatController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.someneat',

    // this is bound to a button click event, let's say.
    onClick: function(button) {

        // How to get a reference to a global controller here? 
        // this.getController('TargetController'); is not defined
        // on the view controller....

    }

});

Probably something simple I'm missing, but any help would be appreciated.

Share Improve this question edited Sep 7, 2015 at 20:30 Tarabass 3,1502 gold badges19 silver badges35 bronze badges asked Jun 9, 2014 at 13:32 Kyle FranshamKyle Fransham 1,8791 gold badge19 silver badges22 bronze badges 4
  • In 99.99% cases, if you need to get a reference to a global controller in Ext JS 5 you're doing something wrong. What was the intent? – Alex Tokarev Commented Jun 13, 2014 at 17:16
  • I thought someone was going to ask this. :) I have to retrieve some data from a webservice (google drive api) and I have this logic (with all of the oauth2 stuff) nicely abstracted into a contoller from a previous ExtJS4 project. I need to kick off that data retrieval from an event that I'm handling in the view controller. It might not be the 100% ideal architecture, but refactoring working, tested, (and pretty) code just to fit a design pattern is even less desirable, in my opinion. – Kyle Fransham Commented Jun 13, 2014 at 20:18
  • 1 Controller event domain is the tool to use here. See my posts: nohuhu/development/controller-events-in-ext-js-4-2 and nohuhu/development/… – Alex Tokarev Commented Jun 14, 2014 at 22:08
  • Neat. That wasn't on my radar before. One small bug in the ext 5.0.0 documentation: The Ext.app.EventDomain class lists the controller domain as all classes extending from Ext.app.Controller. The view controllers do NOT extend from Ext.app.Controller, (though both share a mon Ext.app.BaseController base) but the controller event domain DOES listen to events fired from view controllers. Anyways, thanks for the tip. – Kyle Fransham Commented Jun 16, 2014 at 13:47
Add a ment  | 

1 Answer 1

Reset to default 5

Calling getController on your namespace should work:

myCoolApp.app.getController('TargetController');`

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745351590a4623864.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信