Jquery – Jstree get all child node

jqueryjstree

I am using Jstree plugin and i want to get the all child node of the selected node without expanding it.
I googled little bit and came know that it can be done using below code.

checked = $("#tree").jstree("get_checked",null,true) ;

But its not working for me, I need to expand/open node first in order to get its children.

Here is sample code that i am using

$("#treeview-CarrierGroup").jstree("get_checked", null, true).each(function (item) {
alert($(this).attr("id"));
});

Please let me know if its possible to get child node of selected parent node without expanding/opening it.

Thank

Best Answer

It looks like you are using the wrong method for a start. .get_checked ( context, get_all ) is part of the checkbox plugin. You want ._get_children ( node ). Docs for core of jstree1

Also, if you are using lazy loading and a node is not loaded, you will not be able to get its children in this fashion because they simply do not exist yet. That is possibly why you are seeing a difference between before and after you have expanded the node. There are various solutions to this:

You could manually load the node before getting its children.

Or if you are simply after the list of children and don't really need to visualize it in the jstree, you could use another ajax call to get this information independantly of the jstree.