jsTree Open a branch
Your code for open branch is correct.
For example. Source of tree:
<div id="treeTask">
<ul>
<li id="node_37"><a href="#">TEST1</a>
<ul>
<li id="node_38"><a href="#">TEST2</a></li>
<li id="node_39"><a href="#">TEST3</a></li>
</ul>
</li>
</ul>
</div>
Open node:
$("#treeTask").jstree("open_node", $("#node_38"));
Here is function that can open a specific node and all its parents.
function expandNode(nodeID) {
// Expand all nodes up to the root (the id of the root returns as '#')
while (nodeID != '#') {
// Open this node
$("#jstree").jstree("open_node", nodeID)
// Get the jstree object for this node
var thisNode = $("#jstree").jstree("get_node", nodeID);
// Get the id of the parent of this node
nodeID = $("#jstree").jstree("get_parent", thisNode);
}
}
You could use the binding
$("#tree").bind("open_node.jstree", function (event, data) {
if((data.inst._get_parent(data.rslt.obj)).length) {
data.inst._get_parent(data.rslt.obj).open_node(this, false);
}
});
Try this code to open node till nth Level
$("#myTree").jstree({options}).bind('loaded.jstree', function (e, data) {
/**
* Open nodes on load (until x'th level)
*/
var depth = 3;
data.inst.get_container().find('li').each(function (i) {
if (data.inst.get_path($(this)).length <= depth) {
data.inst.open_node($(this));
}
});
});