How to remove child nodes of selected node in jstree?

I find it difficult to remove the child nodes of the 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 also removes the selected node. How to remove only the child nodes of the selected node, and not the selected node?

+2
source share
1 answer

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

Unfortunately, I believe that the solution should be something like:

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

Source: https://habr.com/ru/post/1680768/


All Articles