Delete all nodes in jsTree

て烟熏妆下的殇ゞ 提交于 2019-12-05 11:51:10

问题


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?


回答1:


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.




回答2:


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.




回答3:


$('#tree').jstree("destroy").empty();

This is what worked for me. First destroy jstree elements and associated events, and then empty the div containing jstree.




回答4:


Call .remove(node) on the root nodes.




回答5:


The following call will destroy the current instance of jsTree, remove any bound event listeners and obviously achieve your ultimate goal of removing all nodes. But this method is a bit of a over-kill, it has to be said.

$("#DivElementContainingYourTree").jstree("init");



回答6:


$('#jstree').parent().html('<div id="#jstree"></div>');



回答7:


myTree.delete_node(myTree.get_node("#").children);


来源:https://stackoverflow.com/questions/6297852/delete-all-nodes-in-jstree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!