How to remove child nodes of selected node in jstree?

时光毁灭记忆、已成空白 提交于 2019-12-10 11:28:55

问题


I am facing difficulty in deleting child nodes of a selected node.

$(function () {
$("#tree").jstree({ 
    "json_data" : {
        "data" : [
            { 
                data : "/", 
                attr : { "id" : "root"},
                state : "closed",
                "children" : [ { "data" : "child1",
                                "attr" : { "id" : "child1.id" },
                                "children" : [ ] }
                             ]
            },
        ]
    },
    "plugins" : [ "themes", "json_data", "crrm", "ui" ]
})

I am using $("#tree").jstree("remove", data.rslt.obj); to remove the child nodes below the node itself but it also deletes the node selected. How can I delete the just child nodes of a selected node and not the selected node ?


回答1:


As @Redtopia correctly pointed out, jsTree does not have the cleanest API.

Unfortunately, I believe that the solution will have to be something like:

$("#tree").jstree("remove",data.rslt.obj.find('li'));


来源:https://stackoverflow.com/questions/18861654/how-to-remove-child-nodes-of-selected-node-in-jstree

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