如何在jquery Jstree中打开所有节点? [英] How do i open all nodes in jquery Jstree?
问题描述
我正在使用以下代码:
$("#treeview").jstree();
$("#treeview").jstree('open_all');
使用以下html:
<div id="treeview">
<ul>
<li>
<a href="#">rubentebogt</a>
<ul>
<li>
<a href="#" onclick="goTo('index.php?module=alarm&pagina=dashboard&id=6',false);">Beneden</a>
</li>
<li>
<a href="#" onclick="goTo('index.php?module=alarm&pagina=dashboard&id=7',false);">Boven</a>
</li>
</ul>
</li>
</ul>
</div>
我的问题是所有节点都保持关闭状态,我无法用jstree打开它们(' open_all');
My problem is that all nodes stay closed, i can't get them to open with jstree('open_all');
推荐答案
jsTree文档是次优的。文档没有明确说明初始化是异步工作的。有 core.loaded():
The jsTree documentation is "sub optimal". The docs don't clearly state that the initialization works asynchronously. There's core.loaded():
一个虚函数,其目的只是触发加载的事件。加载树的根节点后,但在打开在initial_open中设置的任何节点之前,会触发此事件。
A dummy function, whose purpose is only to trigger the loaded event. This event is triggered once after the tree's root nodes are loaded, but before any nodes set in initially_open are opened.
这表示事件树设置后会触发 loaded.jstree
。您可以挂钩该事件以打开所有节点:
This suggests an event loaded.jstree
is fired after the tree is setup. You can hook into that event to open all your nodes:
var $treeview = $("#treeview");
$treeview
.jstree(options)
.on('loaded.jstree', function() {
$treeview.jstree('open_all');
});
这篇关于如何在jquery Jstree中打开所有节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!