PDA

View Full Version : Reader Extend



elcooleperco
26 Apr 2013, 3:06 AM
I have extended reader for read flat model

Ext.define('Snui.model.DictItem', { extend: 'Ext.data.Model',
idProperty: 'Id',
fields: [
{ name: 'Id', type: 'int'},
{ name: 'ParentId', type: 'int'},
{ name: 'Name', type: 'string' },
{ name: 'leaf', type: 'boolean', defaultValue: false},
]
})
Ext.define('Snui.reader.FlatTreeReader',{
extend: 'Ext.data.reader.Json',
requestRoot: 'DictDataResult',
defaultRoot: 'children',
alias: 'reader.flattreereader',
constructor: function(cnfg){
if(!cnfg)
cnfg={};
this.callParent(arguments);
this.initConfig(cnfg);
},
getData: function(data){
var me = this;
var treedata = {};
var root = root||this.defaultRoot;
data = (Ext.isString(data) && Ext.decode(data)) || data;
function ParentFilter(element, index, array){
return element.ParentId == this.filterId;
};

function BuildTree(list, filter, parent){
var tmp = list.filter(ParentFilter, filter);
if(tmp && tmp.length)
{
if(!parent[root])
parent[root]=[];
Ext.Array.push(parent[root],tmp);
}
for(var item in parent[root]){
BuildTree(list, {filterId: tmp[item].Id}, parent[root][item]);
}
};
data && data[me.requestRoot] && BuildTree(data[me.requestRoot], {filterId: null},treedata);
return treedata;
}
})
;
and when i receive answer from server i call reade.getData(response) and i receive right structure.
but if i create store,proxy,reader and then call store.getProxy().getReader().read(data) its return invalid data tree and doesnt put it into my tree store...
any ideas?

slemmon
29 Apr 2013, 1:31 PM
If you've created a custom extension and it's not working as expected / reliably you many need to set breakpoints and walk into the code to see what happens differently between use cases.