PDA

View Full Version : Could not get tree nodes



ckuser
17 Nov 2009, 7:11 AM
Hi,
I want to iterate nodes. But i couldn't

Here is my code;



var tree = new Ext.tree.ColumnTree({
autoScroll : true,
border: true,
header : false,
height : 710,
renderTo : 'passive_column_tree',
rootVisible : false,
//title : ' ',
width : pageWidth,
loader : new Ext.tree.TreeLoader({
dataUrl : 'servlet?cmd=tree',
requestMethod : 'GET',
uiProviders : {
'col' : Ext.tree.ColumnNodeUI
}
}),
root: new Ext.tree.AsyncTreeNode({
id: 'root'
}),

columns : [{header :'customerName', width : 348, sortable : false, dataIndex : 'rowName'
}, {header :'firstAppTypeDate', dataIndex : 'corrected1', width : 134, renderer : Ext.util.Format.numberRenderer('0,000')
}, {header :'secondAppTypeDate', dataIndex : 'corrected2', width : 134, renderer : Ext.util.Format.numberRenderer('0,000')
}, {header :'thirdAppTypeDate', dataIndex : 'corrected3', width : 134, renderer : Ext.util.Format.numberRenderer('0,000')
}],
tbar : [{
text : localize('ccs.common.button.show.detail'),
handler : function() {
tree.expandAll();
}
}, '-',{
text : '1',
handler : function() {
tree.getRootNode().eachChild(function(node){
console.log(node);
});
console.info(tree.getRootNode());
var rootNode = tree.getRootNode();
var rootAtr =rootNode.childNodes[0].attributes;
console.info(rootAtr);
for(i=0; i<rootAtr.children.length; i++){
console.info(rootAtr.children[i].id);
console.info(tree.getNodeById(rootAtr.children[i].id)); //returns null
console.info(rootNode.findChild('id', rootAtr.children[i].id)); //returns undefined
}
}
}, '-',{
text : localize('ccs.common.button.show.summary'),
handler : function() {
tree.collapseAll();
}
}],

Mike Robinson
17 Nov 2009, 9:20 AM
Is the data ... are the nodes ... available yet? That is to say, when your code attempts to run?

"Asynchronous," remember? :-|

ckuser
18 Nov 2009, 12:15 AM
Yes available,
console.info(rootAtr.children[i].id);

returns the id

The data :



[
{
uiProvider:'col',
rowName:'rowname',
corrected1:'1184550',
corrected2:'10611865',
corrected3:'18266035',
id:'1',
children:[
{
uiProvider:'col',
trend:'0.00',
rowName:'rowname',
corrected1:'754182',
corrected2:'6692003',
corrected3:'12914787',
id:'2',
children:[
{
uiProvider:'col',
trend:'0.00',
rowName:'rowname',
corrected1:'145297',
corrected2:'2404503',
corrected3:'6980509',
id:'3',
children:[
{
uiProvider:'col',
trend:'0.00',
rowName:'rowname',
corrected1:'96048',
corrected2:'2079661',
corrected3:'3123492',
id:'4',
leaf:true
},
{
uiProvider:'col',
trend:'0.00',
rowName:'rowname',
corrected1:'0',
corrected2:'0',
corrected3:'0',
id:'5',
leaf:true
},
{
uiProvider:'col',
trend:'0.00',
rowName:'rowname',
corrected1:'49249',
corrected2:'324842',
corrected3:'3857017',
id:'6',
leaf:true
}
]
}
]}
]}
]