简体   繁体   English

获取jstree中子节点的直接父级

[英]Get the immediate parent of child node in jstree

I want to retrieve the parent of the child node without clicking on the tree .. 我想在不单击tree情况下检索child node的父child node

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

Above command give me the immediate parent when we click on the child nodes . 当我们点击child nodes时,上面的命令给我直接的父child nodes

Is there a way to get the parent node without clicking on the child node . 有没有一种方法可以在不单击child node情况下获得parent node child node

Regards, Praque M 问候,Praque M

It seems the "data.inst" was renamed in newer versions to "data.instance". 似乎“ data.inst”已在较新版本中重命名为“ 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). data.instance.get_parent(data.node)返回父级的字符串ID(这对我来说是意外的)。 To get the parent I had to call data.instance.get_node() on the string ID. 要获取父项,我必须在字符串ID上调用data.instance.get_node()

data.instance.get_parent(data.node) is also accessible thru data.node.parent. data.instance.get_parent(data.node)也可以通过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是一个jquery对象,因此命令

parent_node.attr("something");

is the same as 是相同的

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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