Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在选择子节点时在jstree中获取完整的父节点名和子节点名_Javascript_Jquery_Jstree - Fatal编程技术网

Javascript 如何在选择子节点时在jstree中获取完整的父节点名和子节点名

Javascript 如何在选择子节点时在jstree中获取完整的父节点名和子节点名,javascript,jquery,jstree,Javascript,Jquery,Jstree,我正在获取子树id: 但当我选择所有子节点时,我会得到父节点id 我想获得父节点名称的完整层次结构 例如:- node 1 >node 1 child node 1 node 1 >node 1 child node 2 这是我的全部代码 <div id="demo1" class="demo"> <ul> <li id="phtml_1"> <a href="#">node 1</a>

我正在获取子树id:

但当我选择所有子节点时,我会得到父节点id

我想获得父节点名称的完整层次结构

例如:-

node 1 >node 1 child node 1 

node 1 >node 1 child node 2
这是我的全部代码

<div id="demo1" class="demo">
  <ul>
    <li id="phtml_1">
      <a href="#">node 1</a>
      <ul>
        <li id="phtml_3">
          <a href="#"> node 1 Child node 1</a>
        </li>
        <li id="phtml_2" >
          <a href="#">node 1 Child node 2</a>
        </li>
      </ul>
    </li>
    <li id="phtml_4">
      <a href="#">Root node 2</a>
    </li>
  </ul>

  <script type="text/javascript" class="source">
    $(function () {
      $("#demo1").jstree({ 
        "plugins" : [ "themes", "html_data", "checkbox", "sort", "ui" ]
      });
    });
  </script>
</div>
<h4 id="menu" name="menu">
  click menu
</h4>


<script type="text/javascript">
  $("#menu").click(function() {
    var ids = $('#demo1 li.jstree-checked').filter(function() { 
      return $(this).parents('li.jstree-checked').length == 0; 
    }).map(function() { 
      return this.id;
    }).get();

    alert(ids);

  });
</script>
<script type="text/javascript" src="http://johntang.github.io/JsTree/_lib/jquery.js"></script>
<script type="text/javascript" src="http://johntang.github.io/JsTree/jquery.jstree.js"></script>

$(函数(){ $(“#demo1”).jstree({ “插件”:[“主题”、“html_数据”、“复选框”、“排序”、“ui”] }); }); 单击菜单 $(“#菜单”)。单击(函数(){ var id=$('#demo1 li.jstree checked').filter(函数(){ 返回$(this.parents('li.jstree checked')。长度==0; }).map(函数(){ 返回此.id; }).get(); 警报(ids); });

在此问题上的任何帮助或指导都将不胜感激。

您可以使用
get\u path
方法,如下所示。检查演示-


我回答你的问题了吗?
var glue = ' > ', // if you want a specific string separator, otherwise use false
    showIds = true; // if false names will be shown

$('#tree').jstree().get_path(data.node, glue, showIds )