PDA

View Full Version : treepanel click



Nikolajtesla
27 Oct 2010, 3:36 PM
I have a simple TreePanel.
var menu = new Ext.tree.TreePanel({
id: menu,
autoScroll: true,
animate: true,
enableDD: false,
border: false,
containerScroll: true,
dataUrl: 'get-nodes.php',
rootVisible: false,
root: {
nodeType: 'async',
text: 'Tree Root',
draggable: false,
id: '0'
}
});
Data, which is received via get-nodes.php is structured in the following way:
[{"id":"6","text":"node_2","uri":"uri_1","leaf":false},...,{"id":"1","text":"node_1","uri":"uri_2","leaf":false}]
I need to do the following thing. On click of each node i need to redirect to the uri, this node provided.

I tried something like this. I've added listener into the tree
listeners: {
click: function(node, event){
window.location=node;
}
}

eztam
27 Oct 2010, 10:14 PM
The API of Ext.tree.TreeNode defines the href attribute, so you could rename the uri attribute to href.
Then you can remove your click listener, because the href attribute should automatically link your TreeNode.

Nikolajtesla
27 Oct 2010, 11:07 PM
thank you for help.
It helps, but just curious how can I get some other parameters via JSON?

Animal
27 Oct 2010, 11:32 PM
All properties from the node's JSON definition are put into attributes.

http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreeNode&member=attributes

Nikolajtesla
29 Oct 2010, 5:41 AM
thank you very much.