How to update jstree node values without reload

末鹿安然 提交于 2019-12-20 18:30:33

问题


I have a jstree that I created with the following code:

$('#mytree').jstree({"core": { "data" : value
                             , "themes" : { "dots": false
                                          , "icons": false }
                             }
                    }
                   );

I can rebuild it with new data by this code:

$('#mytree').jstree(true).settings.core.data = new_data;
$('#mytree').jstree(true).refresh();

but it can be expensive when you have a lot of nodes. What I would like to achieve is that I would like update the value of the elements (i.e. the node.text part) without rebuilding the whole tree. I get the new values via websocket in one message (the complete JSON string that will be the new_data) but the structure is not changing. How can I do that? Thank you!


回答1:


What you need is not refresh() but redraw() thus the code is

$('#mytree').jstree(true).settings.core.data = new_data;
$('#mytree').jstree(true).redraw(true);

You can find the functions in the jstree API.

As per zmirc suggestion, in v3.1 use:

$('#mytree').jstree(true).settings.core.data = new_data;
$('#mytree').jstree(true).refresh();



回答2:


for deleting the node and reload tree

 $('#mytree').jstree(true).refresh();

for those who need to redraw without restart the tree use

jQuery('#data').jstree(true).refresh(true);



回答3:


You can refresh node by this

$('#treeView').jstree(true).refresh_node("node_id_here")



回答4:


$('#mytree').jstree(true).refresh(); is working, but in my case it causes thread leak. every refresh adds one more thread




回答5:


I load data via an url, so my refresh part looks like:

$('#groupTree').jstree(true).settings.core.data.url = get_group_url();


来源:https://stackoverflow.com/questions/26532967/how-to-update-jstree-node-values-without-reload

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