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
1 Answer
Reset to default 5Calling getController on your namespace should work:
myCoolApp.app.getController('TargetController');`
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745351590a4623864.html
评论列表(0条)