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

时间:2016-02-20 12:39:33

标签: javascript jquery jstree

我正在获取子树ID:

enter image description here

但是当我选择所有子节点时,我正在获得父节点id。

enter image description here

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

例如: -

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>

对此事项的任何帮助或指导都将不胜感激。

1 个答案:

答案 0 :(得分:1)

您可以使用Tab方法,如下所示。查看演示 - Fiddle

TabPage
相关问题