Jyoti
Jyoti

Reputation: 41

How to check whether selected node is having child nodes or not in jstree?

I m taking selected node by following code.

var selected=$("#warehouseTree").jstree('get_selected');

and now i want to check for child nodes for selected node.

Upvotes: 4

Views: 11275

Answers (4)

Syed Kashan Ali
Syed Kashan Ali

Reputation: 663

This is how you can check whether a node has children or not.

var tree = jQuery.jstree._reference('#warehouseTree');
var isParent = instance.is_parent(selected);
console.log(isParent) //  true for directory

Upvotes: 0

Khateeb321
Khateeb321

Reputation: 2104

This is simply how you extract children information from a specific node.

$("#tree_2").jstree().get_node("13").children

Upvotes: 5

Dan Brooke
Dan Brooke

Reputation: 1577

Try this:

var tree = jQuery.jstree._reference('#warehouseTree');
var children = tree._get_children(selected);

Which will return an array of jQuery objects of the children of the selected node.

Upvotes: 2

Sarath
Sarath

Reputation: 9156

this will help.

   if(selected.children().size() > 0)
    {
    //has child
    }

Upvotes: 1

Related Questions