如何在页面中打开具有多个jstree的jstree特定节点
How to open jstree specific node having multiple jstree in a page
我在打开 特定 jstree
节点时遇到问题。
我在一个页面中有 多个 jstree
并且想以编程方式控制节点的打开和关闭。
问题:我想以编程方式打开节点 banana?
这是我的代码:
$(function () {
$('.jstree-node').jstree();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
<div id="multiple_jstree_wrapper">
<div class="jstree-node" data-name="apple">
<ul>
<li>Apple
<ul>
<li>Child node 1</li>
<li>Child node 2</li>
</ul>
</li>
</ul>
</div>
<div class="jstree-node" data-name="banana">
<ul>
<li>Banana
<ul>
<li>Child node 1</li>
<li>Child node 2</li>
</ul>
</li>
</ul>
</div>
<div class="jstree-node" data-name="orange">
<ul>
<li>Orange
<ul>
<li>Child node 1</li>
<li>Child node 2</li>
</ul>
</li>
</ul>
</div>
</div>
注意:我想保持相同的树结构
你可以试试:
$('div[data-name="banana"]').jstree("open_all");
我在打开 特定 jstree
节点时遇到问题。
我在一个页面中有 多个 jstree
并且想以编程方式控制节点的打开和关闭。
问题:我想以编程方式打开节点 banana?
这是我的代码:
$(function () {
$('.jstree-node').jstree();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
<div id="multiple_jstree_wrapper">
<div class="jstree-node" data-name="apple">
<ul>
<li>Apple
<ul>
<li>Child node 1</li>
<li>Child node 2</li>
</ul>
</li>
</ul>
</div>
<div class="jstree-node" data-name="banana">
<ul>
<li>Banana
<ul>
<li>Child node 1</li>
<li>Child node 2</li>
</ul>
</li>
</ul>
</div>
<div class="jstree-node" data-name="orange">
<ul>
<li>Orange
<ul>
<li>Child node 1</li>
<li>Child node 2</li>
</ul>
</li>
</ul>
</div>
</div>
注意:我想保持相同的树结构
你可以试试:
$('div[data-name="banana"]').jstree("open_all");