Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Daniel Stoian on May 05, 2008 11:06
open dhtmlx forum
dhtmlxtree: onClick event triggers twice


Hi,

I am currently evaluating the free version of the tree control downloaded from your website, in order to decide whether we can use the commercial version.

I am attaching an event handler for all my tree nodes using:

mytree = new dhtmlXTreeObject(target, "100%", "100%", 0);
[...]
mytree.setOnClickHandler(doOnClickTree);

Using an alert call like so:

function doOnClickTree(id)
{
alert("onclick triggerred");
}

will show that this event triggers twice.

Can you explain why this is happening?

Thanks.
Answer posted by Support on May 08, 2008 03:00
The problem can't be reconstructed with local samples.
Please be sure that tree.setOnClickHandler command executed only once ( each time when such command executed, it adds new one event handler, without removing previous one, so if it was executed twice - it will cause double call of related function )

If problem still occurs for you - please provide any kind of sample where problem can be reconstructed ( you can send it directly to support@dhtmlx.com )
Answer posted by ds on May 08, 2008 07:19

I was rebuilding the tree dynamically, but I forgot to call "detachEvent" before reattaching...

The answer is that one should do:

detachEvent(...)

and only after that:

attachEvent(...)