0

我试图弄清楚 ExtJS4 如何传递配置对象。我想做相当于...

store  = function(config){
    if ( typeof config.call !== 'unndefined' ){
        config.url = "server.php?c=" + config.call || config.url;       
    };  
    Sketch.Data.AutoSaveStore.superclass.constructor.call(this,config);
};
Ext.extend(store, Ext.data.Store{})    

我可能在这里遗漏了一些明显的东西,但是在沙箱文件中进行了挖掘,我最接近的是....

 Ext.define('My.awesome.Class', {
     // what i would like to pass.
     config:{},
     constructor: function(config) {
         this.initConfig(config);
         return this;
     }
 });

如果你做类似的事情,这似乎不起作用......

var awesome = Ext.create('My.awesome.Class',{
    name="Super awesome"
});  
alert(awesome.getName()); // 'awesome.getName is not a function'

然而

  Ext.define('My.awesome.Class', {
     // The default config
     config: {
         name: 'Awesome',
         isAwesome: true
     },
     constructor: function(config) {
         this.initConfig(config);
         return this;
     }
 });

var awesome = Ext.create('My.awesome.Class',{
    name="Super awesome"
});  
alert(awesome.getName()); // 'Super Awesome'

在尝试进行复杂的商店扩展时,这在后端咬了我一口。有人知道我如何将一堆随机参数传递给原型吗?

4

1 回答 1

5

您不应该使用 new 运算符在您的类上创建新实例。在 ExtJS4 中,你应该使用Ext.create()方法。

尝试做:

var awesome = Ext.create('My.awesome.Class');
alert(awesome.getName());

如果您想在创建实例时传递一些参数,您可以执行以下操作

var awesome = Ext.create('My.awesome.Class',{name:'New Awesome'});
于 2011-05-24T09:32:20.480 回答