Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jstree jquery plugin - Get all child and sub child nodes of parent

I am using the jsTree jquery plugin

I am trying to fetch all the nodes and sub nodes of a selected parent. But somehow it's not working unless I use recursion. Is there a better way inherent to jsTree?

like image 333
Sid Avatar asked Jul 16 '12 20:07

Sid


2 Answers

You can get full tree all by using this selector: $("#demo1").find("li > a")

like image 192
Arkadiusz 'flies' Rzadkowolski Avatar answered Oct 04 '22 21:10

Arkadiusz 'flies' Rzadkowolski


I tried the previous solution and it is not working with the latest version of jsTree (v3.2.1). Below is an updated solution to get the child nodes and sub nodes of the parent.

$("#myTree").bind('selected_node.jstree', function (node, data) {
    var selectedNodes = $("#myTree").jstree(true).get_json(data.node.id, { flat: true });
    for (var i = 0; i < selectedNodes.length; i++) {
       // Apply logic here
       // ...
       // ...
       // ...
    }
});
like image 35
usr4896260 Avatar answered Oct 04 '22 21:10

usr4896260