Reputation: 4120
I have a (js)Tree which is deep 3 levels or more. Although I have the entire tree data pre-loaded, the tree is collapsed, except for the root node. On a specific js event, I want to expand a particular node (I have its ID/selector). How would I go about it?
At the moment I can only:
placeholder.find(".jstree").jstree("open_all");
placeholder.find(".jstree").jstree("select_node", "[data-xxx = '" + yyy + "']");
which expands EVERYTHING and selects the given node. I want to achieve the same thing, but expanding only the branch(es) which lead to my node.
To put it in pictures, what my code does is:
I am using the latest version of jsTree.
Upvotes: 1
Views: 2052
Reputation: 3886
You should use the _open_to
function. Provided you have the node ID it should be pretty straightforward:
placeholder.find(".jstree").jstree(true)._open_to("NODE_ID_HERE");
Here are the docs on this function: https://www.jstree.com/api/#/?q=_open_to&f=_open_to%28obj%29
EDIT: if you also want to select the node, calling select_node
will be enough, as it will open the parents of the node by default.
Upvotes: 3