Get the immediate parent of child node in jstree

匆匆过客 提交于 2019-12-19 10:13:30

问题


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


回答1:


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);
  }
});



回答2:


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");


来源:https://stackoverflow.com/questions/12914841/get-the-immediate-parent-of-child-node-in-jstree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!