【发布时间】:2012-02-04 07:36:18
【问题描述】:
我正在使用 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"
}
});
看了Data view in Sencha touch之后,我添加了autoLoad和itemSelector,还是不行。
虽然跑步
new majestic.store.Dataset().each(function(i) {console.log(i)});
输出具有填充数据属性的对象列表。
更新
我同意@fbrandel 的第一个选项是它应该如何工作,但是在阅读 ST 源之后,我发现 dataview 的 store 参数被解释为:
- 存储对象
- json 存储符号,如第一个示例 here
- 可以使用StoreManager.lookup解析的已创建商店的名称
所以我最终得到:
- 将
store:'Dataset'留在视图中 - 将
storeId : "Dataset"添加到store,这样可以通过StoreManager解决 - 添加导致创建
majestic.store.Dataset的stores: ['Dataset']并将其注册到StoreManager 中
P.S. 也可以在 GridView 的 initialization 方法中使用 this.setStore(new majestic.store.Dataset()) 来完成,但我更喜欢可能的声明方式
【问题讨论】:
标签: store dataview sencha-touch-2