Get the immediate parent of child node in jstree

感情迁移 提交于 2019-12-01 10:46:39

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

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