2

你能告诉我为什么这让我

无法调用未定义的子字符串。无法调用未定义的方法getModel

Ext.require(                   
    ['MyApp.controller.Country', 'MyApp.controller.CountryProperties'],     // this auto-loads all dependencies 
    function(){ 
            // ... as soon as this class 
            //    and all its dependencies have loaded...
        var controller = Ext.create('MyApp.controller.Country');  // create an instance
        var controller2 = Ext.create('MyApp.controller.CountryPropeties');  // create an instance
        controller.init();                  // launch init() method
        controller2.init();
    }
);

但是,当我在 app.js 中手动将这些控制器、视图、存储和模型添加到控制器:[]、视图:[] 等时,它就可以工作了。

顺便提一句。我有内部控制器 - > stores:[], views: [] 所以当我只加载一个控制器时,它应该加载控制器的任何依赖项。

为什么我得到那个错误?

谢谢你。:)

4

3 回答 3

3

除了@arshabh 答案之外,这是完全正确的。

如果你打电话(rev 1. - 修正错字)

this.application.getController('Country');
this.application.getController('CountryPropeties');

从您的控制器中,您会得到与执行此操作完全相同的结果,只是更简单一些。请注意,应用程序 getter 会自动加载缺少的类,并为控制器或存储初始化/注册它们。

于 2012-12-06T10:53:40.873 回答
0

您的代码很完美,但您忘记了范围(this)

请在代码中做一些小改动,如下所示

    Ext.require(                   
['MyApp.controller.Country', 'MyApp.controller.CountryProperties'],     // this auto-loads all dependencies 
function(){ 
        // ... as soon as this class 
        //    and all its dependencies have loaded...
    var controller = Ext.create('MyApp.controller.Country');  // create an instance
    var controller2 = Ext.create('MyApp.controller.CountryPropeties');  // create an instance
    controller.init();                  // launch init() method
    controller2.init();
},this
   );
于 2012-12-06T09:07:05.730 回答
0

对我有用的是

this.application.getController('Country').doInit(this);

干杯
埃德加

于 2015-04-24T00:37:18.000 回答