我有一个这样的 JSON。
{
"children":[
{"name": "subdivision1","id": "subdiv1","type": "subdiv","children":[
{"name": "Scheme1","id": "scheme1","type": "scheme","children":[
{"name": "Nathuji","id": "nathuji","type": "datalogger","leaf":true},
{ "name": "Tarsang","id": "tarsang","type": "datalogger","leaf":true},
{ "name": "Mithapur","id": "mithapur","type": "datalogger","leaf":true},
{ "name": "Samali","id": "samali","type": "datalogger","leaf":true}]},
{"name": "Scheme2","id": "scheme2","type": "scheme","children":[
{ "name": "Bhunidra","belongsto": "scheme2","id": "bhunidra","type": "datalogger","leaf":true},
{ "name": "Chhogala","belongsto": "scheme2","id": "chhogala","type": "datalogger","leaf":true}]
}]},
{"name": "subdivision2","id": "subdiv2","type": "subdiv","children":[
{"name": "Scheme3","id": "scheme3","type": "scheme","children":[
{ "name": "Thana Savli","belongsto": "scheme3","id": "thanasavli","type": "datalogger","leaf":true},
{ "name": "Padardi","belongsto": "scheme3","id": "padardi","type": "datalogger","leaf":true}]
}]}]}
像这样的模型。
Ext.define('DemoApp.model.dataloggerhierarchymodel',{
extend: 'Ext.data.Model',
fields: ['name','id','type'],
proxy: {
type: 'ajax',
api: {
read: 'data/allschemes.json'
},
reader: {
type: 'json',
root: 'children'
}
}
});
像这样存放。
Ext.define('DemoApp.store.dataloggerhierarchystore',{
extend: 'Ext.data.TreeStore',
model: 'DemoApp.model.dataloggerhierarchymodel',
autoLoad: true,
listeners: {
load:function(){
console.log('Datalogger Tree store loaded');
}
},
root: {
expanded: true
}
});
我在控制器中访问它,例如,
var schemesStore = this.getDataloggerhierarchystoreStore();
if(schemesStore == null || schemesStore == undefined){
console.log('Store Undefined');
}
for(var i = 0; i< schemesStore.count();i++)
{
console.log('Record - '+schemesStore[i].get('id'));
};
schemesStore.each(function(currentRecord){
console.log(currentRecord.get('id'));
});
我在树形面板中显示它,它工作正常。现在我想从商店访问每条记录。但我得到的错误count()
不是函数。在 , 的情况下也是totalCount()
如此each()
。我在这里想念什么?如何从商店访问个人记录?