I have a JSON like this.
{
"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}]
}]}]}
Model like this.
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'
}
}
});
Store like this.
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
}
});
I am accessing it in the controller like,
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'));
});
I am displaying it in a tree panel and it works fine. Now I want to access each record from the store.
But I am getting the error count() is not a function. The same in case of totalCount(), each(). What am I missing here? How can I access individual records from the store?
Unfortunately,
Ext.data.TreeStoreis not a subclass ofExt.data.Store. It doesn’t have all of the methods that normal stores do. In order to access data, you have to access the root node by usinggetRootNode()and using the methods defined inExt.data.NodeInterface.NodeInterface provides the
cascadeBy()method as an equivalent ofeach(), and you’ll have to use it to code your owncount()method.