RTB*_*RTB 40 javascript jquery jstree
我正在使用以下代码:
$("#treeview").jstree();
$("#treeview").jstree('open_all');
Run Code Online (Sandbox Code Playgroud)
使用以下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>
Run Code Online (Sandbox Code Playgroud)
我的问题是所有节点都保持关闭状态,我无法用jstree打开它们('open_all');
rod*_*ehm 59
该jsTree文档是"次优".文档没有明确说明初始化是异步工作的.有core.loaded():
一个虚函数,其目的只是触发加载的事件.加载树的根节点后,但在打开在initial_open中设置的任何节点之前触发此事件.
这表明loaded.jstree
在树设置后会触发事件.您可以挂钩该事件以打开所有节点:
var $treeview = $("#treeview");
$treeview
.jstree(options)
.on('loaded.jstree', function() {
$treeview.jstree('open_all');
});
Run Code Online (Sandbox Code Playgroud)
atm*_*ino 27
我正在使用jstree和Chrome的第3版.加载的事件对我来说不起作用,但即使在创建了jstree实例之后,ready事件仍然有效:
$('#treeview').on('ready.jstree', function() {
$("#treeview").jstree("open_all");
});
Run Code Online (Sandbox Code Playgroud)
http://www.jstree.com/api/#/?q=.jstree%20Event&f=ready.jstree
小智 20
如果要在加载树时打开所有节点:
$("#treeview")
// call `.jstree` with the options object
.jstree({
"plugins" : ["themes", "html_data","ui","crrm","sort"]
})
.bind("loaded.jstree", function (event, data) {
// you get two params - event & data - check the core docs for a detailed description
$(this).jstree("open_all");
})
});
Run Code Online (Sandbox Code Playgroud)
上面的所有答案都不适用于我的工作区.我再次搜索并找到这个链接(为什么jsTree open_all()不适用于我?)是有帮助的,并发布我的回答:
jstree版本:3.0.0-bata10
$(document).ready(function() {
$("#tree").bind("loaded.jstree", function(event, data) {
data.instance.open_all();
});
$("#tree").jstree();
})
Run Code Online (Sandbox Code Playgroud)