How to programmatically select node in jsTree and open all parents

In multi-level jsTree, how to select a specific node (possibly a node sheet) and expand all its parents? Example:
From this JSFiddle ( http://jsfiddle.net/mmeah/fyDE6/ ) I want to programmatically select Grand Child and open all the parent nodes.

In some context, I am trying to ensure that the user returns to the correct node in the tree if there is a deep link to my site

+5
source share
2 answers

jsTree provides an open_node () function to arbitrarily run any node to open. Just scan the tree for non-open parents and open them.

: http://jsfiddle.net/mmeah/yyy8W/

$("#findChild").click(function(){
    $.jstree._reference(myTree).open_node("#Node_001",function(){;},false);
});
$("#findGrandChild").click(function(){
    var closedParents = $("#Node_003").parents("li.jstree-closed");
    for(var i=closedParents.length-1;i>=0;i--){
        pleaseOpen($(closedParents[i]));
    }
});

function pleaseOpen(thisNode){
    if(typeof thisNode=="undefined") return;
    if(thisNode.hasClass("jstree-leaf") || thisNode.hasClass("jstree-open") ) return;
    $.jstree._reference(myTree).open_node(thisNode,function(){;},true);
}

+4

, ,

node

$("#tree").jstree("select_node", selector).trigger("select_node.jstree");

, , ...

$("#tree").jstree(...).bind("loaded.jstree", function () 
{
    $("#tree").jstree("select_node", selector).trigger("select_node.jstree");
});
+2

All Articles