jsTree : How to get IDs of selected nodes to root node in jsTree?

前端 未结 2 1572
醉话见心
醉话见心 2020-12-15 09:37

How to get IDs of selected nodes to root node in jsTree?

Assume C is selected node then How can I get All parent IDs of C.

A

  • B

2条回答
  •  青春惊慌失措
    2020-12-15 09:55

    1 More easy solution

     .get_path ( node , id_mode )
    

    return the path to a node, either as an array of IDs or as an array of node names. mixed node : This can be a DOM node, jQuery node or selector pointing to an element within the tree, whose path we want.bool id_mode : If set to true IDs are returned instead of the names of the parents. Default is false.

    // To get path [ID or Name] from root node to selected node 
    
    var ids = data.inst.get_path('#' + data.rslt.obj.attr('id'),true);
    
    // Returns IDs from root to selected node
    
    var names = data.inst.get_path('#' + data.rslt.obj.attr('id'),false); 
    
    // Returns Name's from root to selected node 
    
    alert("Path [ID or Name] from root node to selected node = ID's = "+ids+" :: Name's = "+names);
    

提交回复
热议问题