简体   繁体   中英

Get selected node's parent in FancyTree

I'm working on FancyTree.js for my current project. 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. 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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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