将配置传递给ExtJS原型

Ale*_*lex 0 config extjs4

我想弄清楚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{})    
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

然而

  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'
Run Code Online (Sandbox Code Playgroud)

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

Abd*_*oof 5

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

尝试做:

var awesome = Ext.create('My.awesome.Class');
alert(awesome.getName());
Run Code Online (Sandbox Code Playgroud)

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

var awesome = Ext.create('My.awesome.Class',{name:'New Awesome'});
Run Code Online (Sandbox Code Playgroud)