Sencha Touch:如何动态加载控制器

时间:2013-09-21 05:39:19

标签: extjs sencha-touch sencha-touch-2

我正在构建一个sencha touch应用程序,其中我要求动态加载控制器(以编程方式),而不是通过在app.js中定义它。

1 个答案:

答案 0 :(得分:5)

试试这段代码:

Ext.require(controller, function() {//controller - "App.controller.Name"
    var c = Ext.create(controller, {application: this}), controllers;
    c.init();
    c.launch();
    /*
    The "getController" returns "undefined" for a dynamically loaded controller, so the "controllerInstances" should be updated.
    */
    controllers = this.getControllerInstances();
    controllers[controller] = c;
    this.setControllerInstances(controllers);
}, this.getApplication());