View Full Version : Append an event to dinamic tree

8 Jul 2010, 5:10 AM
hi guys,

I have a tree who is loaded from a json store, I append events to the root by a listener in the tree definitions, but I dont know how to add a click event for example to a node who is loaded from the json store...


8 Jul 2010, 5:27 AM
You can add the handlers by hooking onto the TreePanel's 'append' event.

new Ext.tree.TreePanel({
listeners: {
'append' : function(tree, parent, node) {
node.on( 'click', function(n, e) {
alert( 'I am node ' + n.text + ' and I was clicked!' );
/* ... rest of configuration ... */

8 Jul 2010, 5:32 AM
Trees don't use stores. What exactly are you using?

8 Jul 2010, 10:58 PM
my mistake, its not a store its a dataurl, and the data is json...

8 Jul 2010, 11:05 PM
But I can't understand your first post. What is your question?

8 Jul 2010, 11:09 PM
Why do you want to add a click event to every node? Why not add a single click event handler to the tree itself?

8 Jul 2010, 11:20 PM
The nodes are loaded from de dataurl, that is json webservice. It populates the nodes, but some are populates some times and others no...it depends the json webservice. What I want is when some kind of node(for me is a kind node, really is that I want a specific node) is populated a click event will add to this node.

8 Jul 2010, 11:23 PM
You want a click listener?


8 Jul 2010, 11:36 PM
yes but I dont know how to add in the dataurl, the icons and the other properties are passed by the dataurl...but the listener arent taken. This is a node in the dataurl that works:

And i try to add the listener, but it doesnt work:

{"id":"1sensor_0variable_0","text":"Value","iconCls":"data","leaf":true,"draggable":false,"href":"","hrefTarget":"","hidden":false,"listeners":"click: function(node, e){addPunto();}

(in the example the nodes are different)

8 Jul 2010, 11:48 PM
I'm going to give up soon. You aren't making sense.

You want to react to click events on tree nodes?

Add a click listener to the TreePanel as I suggested in my link.

9 Jul 2010, 3:20 AM
Ok... I'll try to make the question in another way...

How can I make a tree which is loaded from a json dataurl, and give to each node acustom event..

9 Jul 2010, 3:22 AM
You don't. You write a single click event handler for the tree and do something different based on the node that is passed as the parameter.

10 Jul 2010, 2:06 AM
ok... I think I can solve my problem with this answer...thankkyou very much....
That's make me wonder how can I get some characters from a string.... I mean my node.id is for example...
1_spot_2sensor_5_variable....how can I extract "sensor" from this string in extjs ...the command substring didnt work..

10 Jul 2010, 2:54 AM
Nodes can contain any properties you like apart from text, cls, href etc. You can put any info you like in there.

In the click handler look in thePassedNode.attributes for those extra, informational properties.