PDA

View Full Version : Accessing data in a Treestore of a NestedList after coming back from the server



torsten.t
15 Oct 2010, 8:46 AM
After getting back the data from the server, I try to access the data in an AfterRender event

afterRender: function(list){
console.dir ( store.tree.root.childNodes );
console.dir ( store.tree.root.childNodes[0] );
}

The data I got back looks like:
{"text":".","children":[{"fileName":"locale","id":"locale","cls":"folder","queryStr":"gg=hh"},{"fileName":"data","id":".\/data","cls":"folder"}]}

I want to reach the gg=hh in the field "queryStr".
console.dir ( store.tree.root.childNodes );
gives me an Array with two objects, but
console.dir ( store.tree.root.childNodes[0] );
gives me an "undefined"?
Why do I get an undefined, although the array has two entries?

When I open the array in
console.dir ( store.tree.root.childNodes );
and open the first Element in the console further to 0.attributes.record.data
I see queryStr: "gg=hh"
How can I access the data in the treestore after is has been filled from the server?
Any help would be appreciated.
Torsten


Ext.regModel('File', {
idProperty: 'id',
fields: [{
name: 'id',
type: 'string'
}, {
name: 'fileName',
type: 'string'
}, {
name: 'queryStr',
type: 'string'
}]
});

Ext.setup({
icon: 'icon.png',
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
glossOnIcon: false,
onReady: function(){
var store = new Ext.data.TreeStore({
model: 'File',
proxy: {
type: 'ajax',
url: '/cgi-bin/nested.cgi?bb=cc',
reader: {
type: 'tree',
root: 'children'
}
}
});

var nestedList = new Ext.NestedList({
fullscreen: true,
listeners: {
afterRender: function(list){
console.dir ( store.tree.root.childNodes ); // <- here I get the array
console.dir ( store.tree.root.childNodes[0] ); // <- here I get undefined
}
},
title: 'src/',
displayField: 'fileName',
// add a / for folder nodes in title/back button
getTitleTextTpl: function(){
return '{' + this.displayField + '}<tpl if="leaf !== true">/</tpl>';
},
// add a / for folder nodes in the list
getItemTextTpl: function(){
return '{' + this.displayField + '}<tpl if="leaf !== true">/</tpl>';
},
store: store
});

}
});