在jstree中获取子节点的直接父节点 [英] Get the immediate parent of child node in jstree

查看:119
本文介绍了在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");

当我们点击子节点时,上面的命令给我直接的父节点

有没有办法获得父节点而无需点击子节点

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

问候,
Praque M

Regards, Praque M

推荐答案

似乎data.inst在较新版本中被重命名为data.instance。这使得难以追踪解决方案

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)返回字符串ID父母(对我来说很意外)。要获取父级,我必须在字符串ID上调用 data.instance.get_node()

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)也可通过data.node.parent访问。

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

示例:

$('#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);
  }
});

这篇关于在jstree中获取子节点的直接父节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆