Is there a way to clear out all nodes from a jsTree that's faster than walking through all the nodes deleting them one-by-one?
The simplest way I have found is to simply call .empty
on the div containing the tree.
$('#tree').empty();
You might choose to use a more specific selector as a parameter for empty()
, but this works fine for me.
$('#tree').jstree("destroy").empty();
This is what worked for me. First destroy jstree elements and associated events, and then empty the div containing jstree.
See the documentation here: http://www.jstree.com/documentation/core
.delete_node ( node )
Removes a node. Triggers an event.
mixed node
This can be a DOM node, jQuery node or selector pointing to the element you want to remove.
It seems you can just do a selector that will delete all the nodes you want, no loops required.
myTree.delete_node(myTree.get_node("#").children);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With