如何在不重新加载的情况下更新jstree节点值 [英] How to update jstree node values without reload
问题描述
我有一个使用以下代码创建的jstree:
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();
,但是当您有很多节点时,它可能会很昂贵.我想实现的是我想在不重建整个树的情况下更新元素的值(即node.text
部分).我通过websocket在一条消息中获得了新值(完整的JSON字符串将为new_data
),但是结构没有改变.我怎样才能做到这一点?谢谢!
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!
推荐答案
您需要的不是refresh()
,而是redraw()
,因此代码是
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);
您可以在 jstree API 中找到这些功能.
You can find the functions in the jstree API.
按照zmirc的建议,在v3.1中使用:
As per zmirc suggestion, in v3.1 use:
$('#mytree').jstree(true).settings.core.data = new_data;
$('#mytree').jstree(true).refresh();
这篇关于如何在不重新加载的情况下更新jstree节点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!