How do I split constructed jstree into 2 parts

末鹿安然 提交于 2019-12-12 04:18:55

问题


I am using jstree and jstree grid for contructing my tree structure. Can I split the constructed jstree into 2 parts?


回答1:


You can split it with code as below. Check demo: Fiddle

$("#tree1")
    .on("select_node.jstree", function(e, data) {

        // destroy second tree and remove DOM elements
        if ($("#tree2").find('ul').length > 0) {
            $("#tree2").jstree('destroy').empty();
        }

        // get json format for branch to move selected node/branch from first tree
        var json = data.instance.get_json(data.node);

        // init second tree with new data
        $("#tree2").jstree({
            "core": {
                "data": json
            }
        });

        // remove selected node/branch from the first tree
        $("#tree1").jstree('delete_node', [data.node.id]);
        $("#" + data.node.id).remove();

    })
    .jstree({
        "core": {
            "data": data1
        }
    })


来源:https://stackoverflow.com/questions/34940429/how-do-i-split-constructed-jstree-into-2-parts

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