开发者

Is there a way to get all controllers in an ExtJS 4.0 application

开发者 https://www.devze.com 2023-04-06 06:34 出处:网络
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 tryin

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
});
0

精彩评论

暂无评论...
验证码 换一张
取 消