Closed jonaswindey closed 10 years ago
It's better to call the initialization function only once. You can load new data in the tree using the loadData method.
$('#tree').tree('loadData', data);
I hope this works.
Fixed in the dev branch: if you initialize the tree multiple times, then the events must not be trigger multiple times.
I'm having an issue with events that are triggered multiple times when a tree is initliazed multiple times.
function createTree(data) { $('#tree').tree({ data: data, dragAndDrop: true, autoOpen: true, }); }
$('#tree').bind( 'tree.select', function(event) { // some ajax and logic here }
This works perfect the first time. However, in my application, I call createTree multiple times (when data has been updated externally from an ajax call). This triggers multiple times the 'tree.select' event, which is not the expected behaviour, since it calls multiple times my logic (and servercalls)
Ofcourse I could set a variable isCalled and check that on each event, but that sounds dirty.
I've tried using $('#tree').unbind('tree.select'), but that doesn't change.
I also read that jquery's bind() method has been deprecated and replaced by on(), but that gives the same effect (jqTree's docs say to use bind() though)
Any suggestions? Thanks