2012-02-02 67 views
0

我與煎茶玩弄並創建了一個清單,商店和模型:煎茶觸摸 - 擴展存儲 - 構造函數調用

主:

Ext.Loader.setConfig({enabled: true}); 

Ext.application({ 
viewport: { 
    autoMaximize: false 
},                                         
name: 'Sencha',                                         

launch: function() {  
    Ext.create('Ext.List', { 
     fullscreen: true, 

     store: Ext.create('store.Test', { 
     }), 

     itemTpl: '{lastName}, {firstName} Age: {age}' 
    }); 
}                       
}); 

店:

Ext.define('store.Test', { 
extend: 'Ext.data.Store', 

model: 'model.User', 
data: [ 
    { firstName: 'Ed', lastName: 'Spencer', age: 30 }, 
    { firstName: 'Tommy', lastName: 'Maintz', age: 41 }, 
    { firstName: 'Aaron', lastName: 'Conran', age: 24 }, 
    { firstName: 'Jamie', lastName: 'Avins', age: 76 } 
] 
}); 

型號:

Ext.define('model.User', { 
extend: 'Ext.data.Model', 
fields: [ 
    { name: 'firstName', type: 'string' }, 
    { name: 'lastName', type: 'string' } 
] 
}); 

至此,一切正常。

然後,我創建了第二家店,其中有另一個領域'年齡'。我現在想要的是將一個參數「模型」傳遞給商店,以便能夠在不同模型之間「切換」。 我想是這樣的:

店:

Ext.define('store.Test', { 
extend: 'Ext.data.Store', 
myModel: null, 

constructor : function(model) { 
    myModel = model; 
}, 

model: this.myModel, 

data: [ 
    { firstName: 'Ed', lastName: 'Spencer', age: 30 }, 
    { firstName: 'Tommy', lastName: 'Maintz', age: 41 }, 
    { firstName: 'Aaron', lastName: 'Conran', age: 24 }, 
    { firstName: 'Jamie', lastName: 'Avins', age: 76 } 
] 
}); 

,並在主文件:

[...] 
     store: Ext.create('store.Test', { 
      model: 'model.UserWithAge' 
     }), 
[...] 

不過,谷歌給我:

Uncaught TypeError: Object [object Object],[object Object],[object Object],[object Object] has no method 'getRange' 

任何提示我做錯了嗎?

回答

0

沒關係,然後我覺得這很容易。 而是與構造或者這樣說,這是不夠的,只是通過創建存儲時,我媒體鏈接做了模型的東西搞亂:

主:

[...] 
    store: Ext.create('store.Test', { 
     model: 'model.UserWithAge' 
    }), 
[...] 

店:

Ext.define('store.Test', { 
extend: 'Ext.data.Store', 

model: 'model.User', //only set in case that model is not passed when created 

data: [ 
    { firstName: 'Ed', lastName: 'Spencer', age: 30 }, 
    { firstName: 'Tommy', lastName: 'Maintz', age: 41 }, 
    { firstName: 'Aaron', lastName: 'Conran', age: 24 }, 
    { firstName: 'Jamie', lastName: 'Avins', age: 76 } 
] 

} );