I'm building an app using ExtJS 4.0's new MVC architecture. I'm looking for a way to iterate over all the controllers in the app. below I've put some sample code to give an idea of what I'm trying to do.
Ext.application({
name: 'MyApp',
appFolder: '/App',
controllers: [
'HdMenuItemsController'
],
launch: fu开发者_StackOverflow社区nction () {
//This works:
this.getController('HdMenuItemsController')
//I want to do something like this:
this.controllers.each(myFunction);
//or this:
this.getAllControllers().each(myFunction);
//or this:
Ext.getControllersForApp(this).each(myFunction);
}
});
No built in way that I know of (and I am kinda curious why you would need to do this), but you can accomplish this as follows (place this in your launch()
function as you have in your example):
this.controllers.each(function(item, index, length){
var myController = this.getController(item.id);
//now do something with myController!
//OR:
this.getController(item.id).someFunction();
//where someFunction() is defined in all of your controllers
});
精彩评论