PDA

View Full Version : [CLOSED][3.1] tree listener fires for wrong node (off by one)



andynuss
20 Dec 2009, 12:59 PM
Hi,

For 3.1.0 build in firefox, I have a simple test case and a simple in memory tree. Don't know if I'm doing something wrong because I'm a bit of a newbie, but this really seems like a bug. In my tree, the root is not visible, but that doesn't matter. My data in all of the nodes and leafs has extra fields that my app needs, and I'm not sure this matters. I access this data thru node.attributes in the listener for the panel. It doesn't matter whether some of the tree is initially expanded or all of it.

The bug is simple: open the tree and click on the very first node ("Site 2"). It puts up an alert("book") rather than alert("site") indicating that the node event is off by one node. But click "Site 3" node and its ok. Also, use the expander, collapser icon for node "Site 2". It is also off by one, and expands and collapses the first child of that node.



function Home ()
{
var node = {
expanded : true,
text : 'dummy',
leaf : false,
children : my_tree_json,
};
var root = new Ext.tree.AsyncTreeNode(node);
var tree = last_site_panel = new Ext.tree.TreePanel({
renderTo:'tree-div',
id : 'site_panel_id',
animate : false,
layout : 'fit',
root : root,
rootVisible : false, // doesn't matter
title : 'Site Navigation',
listeners : {
click : function (node) {
var typ = node.attributes.mytype;
alert(typ);
},
},
});
return tree;
}

var my_tree_json = [
{
id:2,
text:'Site 2',
leaf:false,
expanded:true,
mytype:'site',
myisdefault:false,
children:[
{
id:2,
text:'Letters and Other Writings of James Madi',
leaf:false,
expanded:true,
mytype:'book',
myisdefault:false,
mytitle:'Letters and Other Writings of James Madi',
mybookid:3,
children:[
{
id:7,
text:'Jane Austen',
leaf:true,
expanded:true,
mytype:'author',
myisdefault:true,
mydisplayname:'Jane Austen',
myid:8
},
{
id:8,
text:'Thomas Hardy',
leaf:true,
expanded:true,
mytype:'author',
myisdefault:false,
mydisplayname:'Thomas Hardy',
myid:2
}
]
},
{
id:3,
text:'The works of John Adams second Presiden-1',
leaf:false,
expanded:true,
mytype:'book',
myisdefault:false,
mytitle:'The works of John Adams second Presiden-1',
mybookid:4,
children:[
{
id:9,
text:'John Updike',
leaf:true,
expanded:true,
mytype:'author',
myisdefault:true,
mydisplayname:'John Updike',
myid:13
}
]
},
]
},
{
id:3,
text:'Site 3',
leaf:false,
expanded:true,
mytype:'site',
myisdefault:true,
children:[
{
id:7,
text:'The diplomatic correspondence of the Uni-1',
leaf:false,
expanded:true,
mytype:'book',
myisdefault:false,
mytitle:'The diplomatic correspondence of the Uni-1',
mybookid:2,
children:[
{
id:18,
text:'Ayn Rand',
leaf:true,
expanded:true,
mytype:'author',
myisdefault:true,
mydisplayname:'Ayn Rand',
myid:5
}
]
},
{
id:8,
text:'Letters and Other Writings of James Madi',
leaf:false,
expanded:true,
mytype:'book',
myisdefault:false,
mytitle:'Letters and Other Writings of James Madi',
mybookid:3,
children:[
{
id:19,
text:'Herman Melville',
leaf:true,
expanded:true,
mytype:'author',
myisdefault:false,
mydisplayname:'Herman Melville',
myid:9
},
{
id:20,
text:'Jane Austen',
leaf:true,
expanded:true,
mytype:'author',
myisdefault:true,
mydisplayname:'Jane Austen',
myid:8
}
]
},
{
id:9,
text:'The Federalist',
leaf:false,
expanded:true,
mytype:'book',
myisdefault:true,
mytitle:'The Federalist',
mybookid:5,
children:[
{
id:21,
text:'Ernest Hemingway',
leaf:true,
expanded:true,
mytype:'author',
myisdefault:true,
mydisplayname:'Ernest Hemingway',
myid:6
}
]
}
]
}
];


Andy

evant
20 Dec 2009, 7:11 PM
Because you have the same id for different nodes in your tree, they need to be unique.

andynuss
20 Dec 2009, 7:21 PM
Thanks a million!