简体   繁体   中英

Get the immediate parent of child node in jstree

I want to retrieve the parent of the child node without clicking on the tree ..

data.inst._get_parent(data.rslt.obj).attr("id");

Above command give me the immediate parent when we click on the child nodes .

Is there a way to get the parent node without clicking on the child node .

Regards, Praque M

It seems the "data.inst" was renamed in newer versions to "data.instance". This made tracking down the solution difficult

data.instance.get_parent(data.node) returns the string ID of the parent (much unexpected for me). To get the parent I had to call data.instance.get_node() on the string ID.

data.instance.get_parent(data.node) is also accessible thru data.node.parent.

Example:

$('#MaterialCollectionTree').on('activate_node.jstree', function(e, data) {
  if(data.instance.is_leaf(data.node)) {
    alert("Leaf: " + data.node.text);
    alert("Parent: " +  data.instance.get_node(data.node.parent).text);
  }
});

It is a bit more complex then that

parent_node = $.jstree._reference('#tree_id')._get_parent(n);

The variable parent_node is a jquery object so the command

parent_node.attr("something");

is the same as

$("#parent_node_id").attr("something");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM