[英]Get selected node's parent in FancyTree
I'm working on FancyTree.js for my current project. 我正在为当前项目使用FancyTree.js。 I need a simple requirement in the Tree. 我在树中需要一个简单的要求。
My requirement is I need to get current selected node's parent node. 我的要求是我需要获取当前选定节点的父节点。 I'm searching everything, but I can't find the solution. 我正在搜索所有内容,但找不到解决方案。
This link about FancyTreeApi has many options. 关于FancyTreeApi的链接有很多选择。 But none of those are related to my requirement. 但是这些都与我的要求无关。
EDITED 已编辑
I have done to get the current selected node using the below code. 我已经完成了使用以下代码来获取当前选定节点的操作。
var node = $("#tree").fancytree("getActiveNode");
if( node ){
alert("Currently active: " + node.title);
}else{
alert("No active node.");
}
I have researched your question and you can do it in some ways: 我已经研究了您的问题,您可以通过以下几种方法来解决:
First: 第一:
var node = $("#tree").fancytree("getActiveNode");
if( node ){
console.log("Parent of FancytreeNode type: ");
console.dir(node.parent);
}else{
console.log("No active node.");
}
where node.parent
is parent tree node 其中node.parent
是父树节点
Second: 第二:
var node = $("#tree").fancytree("getActiveNode");
if( node ){
console.log("Parent of HTMLElement type: ");
console.dir(node.li.parentNode);
}else{
console.log("No active node.");
}
where node.li
is HTML element of active tree node and node.li.parentNode
is it's parent HTML element 其中node.li
是活动树节点的HTML元素,而node.li.parentNode
是其父HTML元素
Use Below code 使用以下代码
This Should be also helpful For You 这也应该对您有帮助
var node = $("#tree").fancytree("getActiveNode");
if( node ){
alert(node.parent);//Give Detail about the parent
alert(node.parent.title);//Give parent node Name
}else{
alert("Select a node First");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.