我正在使用 Sencha touch 2。我已经存储了来自现有 js 对象的负载:
Ext.define('majestic.store.Dataset', {
extend : 'Ext.data.Store',
requires : [
'majestic.model.Dataset',
'majestic.util.config.ConfigurationManager'
],
config : {
model : 'majestic.model.Dataset',
type: 'memory',
reader: 'json',
autoLoad : true,
proxy: {
type: 'memory',
reader: {
type: 'json',
rootProperty : 'datasets'
}
}
},
constructor: function(config) {
this.callParent(arguments);
this.applyData(majestic.util.config.ConfigurationManager.getConfig());
}
});
模型:
Ext.define('majestic.model.Dataset', {
extend : 'Ext.data.Model',
config : {
fields : [
'title'
],
associations: [
{type: 'hasMany', model: 'Layer', name: 'layers'}
]
}
});
并查看:
Ext.define('majestic.view.LayerList', {
requires: ['majestic.store.Dataset'],
extend: 'Ext.dataview.List',
config:{
store: 'Dataset',
itemTpl: '<div>{id} is {title}</div>',
itemSelector: "div"
}
});
在 Sencha touch 中查看数据视图后,我添加了 autoLoad 和 itemSelector,但仍然没有运气。
虽然跑
new majestic.store.Dataset().each(function(i) {console.log(i)});
输出具有填充数据属性的对象列表。
更新
我同意@fbrandel 的第一个选项是它应该如何工作,但是在阅读 ST 源之后,我发现 dataview 的 store 参数被解释为:
- 存储对象
- json 存储符号就像这里的第一个示例一样
- 可以使用StoreManager.lookup解析的已创建商店的名称
所以我最终得到:
- 离开
store:'Dataset'
视野 - 添加
storeId : "Dataset"
到商店,所以它可以由 StoreManager 解决 - 添加
stores: ['Dataset']
导致创建majestic.store.Dataset
并在 StoreManager 中注册的内容
PS它也可以使用GridViewthis.setStore(new majestic.store.Dataset())
的initialization
方法来完成,但我更喜欢可能的声明方式