Destroy removes all instances, how to remove single instance

3,306 views
Skip to first unread message

KK

unread,
Mar 24, 2011, 11:50:44 PM3/24/11
to jsTree
There are multiple instances of jstree in a page and i want to delete
a single instance.

Calling $(#container).jstree('destroy') removes all the instances in
the page ...
as the following from the destroy method forces it to remove
everything
$(document).unbind(".jstree-" + n).undelegate(".jstree-" + n);
instances[n] = null;
delete instances[n];

if i want to remove only a single instance and keep the rest of them.
how do i accomplish the same...
following unbinding of events
$
(#container).unbind(".jstree").undelegate(".jstree").removeData("jstree-
instance-id").find("[class^='jstree']").andSelf().attr("class",
function () { return this.className.replace(/jstree[^ ]*|$/ig,''); });

i want to kill the specific instance


Thanks

mvwd

unread,
Mar 25, 2011, 4:09:59 AM3/25/11
to jsTree
$('#treeID').jstree('destroy'); ...works for me.

I think your working with a selector ('#container'), that matches an
element containing all the trees!? Selecting the tree itself
('#container #tree') should work. Otherwise post a bit more of your
code.

Markus.

KK

unread,
Mar 25, 2011, 1:45:08 PM3/25/11
to jsTree
I couldnt reproduce exact problems in the jsfiddle spike.
I do find that jstree when calling destroy doesnt delete the tree
data, shouldnt the data be cleared out as well just leaving the #demo1
in the original state (without tree ) ?

Here is the jsFiddle
http://bit.ly/fpdfiL

KK

unread,
Mar 25, 2011, 1:56:29 PM3/25/11
to jsTree
As a followup to my above reply ... here is the dom structure that got
left over after destroying demo1

"<ul><li class=" "><ins class="">&nbsp;</ins><a href="#"><ins
class="">&nbsp;</ins>Folder1</a>
<ul><li class=" "><ins class="">&nbsp;</ins><a href="#"><ins
class="">&nbsp;</ins>file1</a></li></ul></li></ul>"

On Mar 25, 12:45 pm, KK <kkgane...@gmail.com> wrote:
> I couldnt reproduce exact problems in the jsfiddle spike.
> I do find that jstree when calling destroy doesnt delete the tree
> data, shouldnt the data be cleared out as well just leaving the #demo1
> in the original state (without tree ) ?
>
> Here is the jsFiddlehttp://bit.ly/fpdfiL

mvwd

unread,
Mar 25, 2011, 2:28:35 PM3/25/11
to jsTree
You'r right, the data will be left over... adding a .remove() will
kill the rest.

$("#demo_1").jstree('destroy').remove();

Don't know if bug or feature ;-)
JsTree-docu says, that destroy() removes the events and classes only.

Markus.

KK

unread,
Mar 25, 2011, 4:09:47 PM3/25/11
to jsTree
I would consider this as a bug since destroy should clean up
everything including the data.
Well i would use empty() instead of remove() as the later would remove
the dom element referenced to build the tree.

mvwd

unread,
Mar 25, 2011, 4:42:01 PM3/25/11
to jsTree
>>Well i would use empty() instead of remove() ...
...yeah, you're right.

Markus.
Reply all
Reply to author
Forward
0 new messages