How to redraw jstree tree with new data?

天大地大妈咪最大 提交于 2019-12-20 11:22:08

问题


So, my question. I initialized my tree with some data:

$('#tree').jstree({
    'core' : {
        'data' : [
            'Simple root node',
            {
                'id' : 'node_2',
                'text' : 'Root node with options',
                'state' : { 'opened' : true, 'selected' : true },
                'children' : [ { 'text' : 'Child 1' }, 'Child 2']
            }
        ]
    });

But after some actions, I want to redraw tree with new data. I try to use refresh and redraw methods from API, but it unsuccessfully.

Can you give me advice, how to refresh tree (without destroy -> create new instance (it works, but it will affect the performance))?


回答1:


At version 3 you can reload the tree :

$('#treeId').jstree(true).settings.core.data = newData;
$('#treeId').jstree(true).refresh();



回答2:


refresh() will refresh the tree to it's initial state, which means that newly created nodes are deleted

What you want is redraw(true)




回答3:


Try including the check_callback parameter in your core settings, (including the initial load) and ensure it is set to true. Then you should be able to see any changes made. Without this, I've found that I'm not seeing the replacement data, just the original data.

$('#tree').jstree({
'core' : {
    'check_callback' : true,
    'data' : [
        'Simple root node',
        {
            'id' : 'node_2',
            'text' : 'Root node with options',
            'state' : { 'opened' : true, 'selected' : true },
            'children' : [ { 'text' : 'Child 1' }, 'Child 2']
        }
    ]
});

That handled the refresh part for me, but depending on what you're doing, you could also call $('#tree').jstree('refresh');.



来源:https://stackoverflow.com/questions/22428921/how-to-redraw-jstree-tree-with-new-data

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