2011-09-21 114 views
2

我正在使用ExtJS 4.0的新MVC體系結構構建應用程序。我正在尋找一種方法來遍歷應用程序中的所有控制器。下面我已經提供了一些示例代碼來說明我正在嘗試做什麼。有沒有辦法讓ExtJS 4.0應用程序中的所有控制器

Ext.application({ 
    name: 'MyApp', 
    appFolder: '/App', 
    controllers: [ 
     'HdMenuItemsController' 
    ], 
    launch: function() { 
     //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); 


     } 
    }); 

回答

0

沒有內置的,我知道的方法(和我有點好奇,爲什麼你需要做到這一點),但你可以做到這一點,如下所示(的地方這在launch()功能,你在你的例子有):

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 
}); 
相關問題