Sencha Touch - 扩展存储 - 构造函数调用
我正在玩 sencha 并创建了一个包含商店和模型的列表:
main:
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}'
});
}
});
store:
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 }
]
});
model:
Ext.define('model.User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'firstName', type: 'string' },
{ name: 'lastName', type: 'string' }
]
});
到目前为止,一切正常。
然后我创建了第二家商店,其中有另一个字段“年龄”。我现在想要的是将参数“模型”传递给商店,以便能够在不同模型之间“切换”。 我尝试了这样的操作:
store:
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'
}),
[...]
但 Google Chrome 给了我:
Uncaught TypeError: Object [object Object],[object Object],[object Object],[object Object] has no method 'getRange'
有什么提示我做错了什么吗?
I'm playing around with sencha and created a list with a store and a model:
main:
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}'
});
}
});
store:
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 }
]
});
model:
Ext.define('model.User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'firstName', type: 'string' },
{ name: 'lastName', type: 'string' }
]
});
To this point everything works fine.
Then I created a second store, which has another field 'age'. What I want now is to pass a parameter 'model' to the store to be able to "switch" between different models.
I tried something like this:
store:
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 }
]
});
and in the main file:
[...]
store: Ext.create('store.Test', {
model: 'model.UserWithAge'
}),
[...]
But Google Chrome gives me:
Uncaught TypeError: Object [object Object],[object Object],[object Object],[object Object] has no method 'getRange'
Any hints what I've done wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系,这比我想象的要容易得多。
不用搞乱构造函数或类似的东西,只需在创建商店时传递模型就足够了,就像我所做的那样:
main:
store:
});
Never mind, it was a lot easier then I thought.
Instead of messing with constructors or something like that it is enough to just pass the model when creating the store as I allready did:
main:
store:
});