2011-09-21 121 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 
}); 
相关问题