Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
22
rated 0 times [  25] [ 3]  / answers: 1 / hits: 62638  / 12 Years ago, wed, june 13, 2012, 12:00:00

I am using the following code:


$("#treeview").jstree();
$("#treeview").jstree('open_all');

With the following html:


<div id="treeview">
<ul>
<li>
<a href="#">RTB</a>
<ul>
<li>
<a href="#" onclick="goTo('index.php?module=alarm&amp;pagina=dashboard&amp;id=6',false);">Beneden</a>
</li>
<li>
<a href="#" onclick="goTo('index.php?module=alarm&amp;pagina=dashboard&amp;id=7',false);">Boven</a>
</li>
</ul>
</li>
</ul>
</div>

My problem is that all nodes stay closed, I can't get them to open with jstree('open_all');.


More From » jquery

 Answers
60

The jsTree documentation is sub optimal. The docs don't clearly state that the initialization works asynchronously. There's core.loaded():




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.




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');
});

[#84936] Tuesday, June 12, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jonrened

Total Points: 627
Total Questions: 114
Total Answers: 99

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
jonrened questions
Mon, Nov 2, 20, 00:00, 4 Years ago
Tue, May 19, 20, 00:00, 4 Years ago
Tue, Jan 21, 20, 00:00, 4 Years ago
Thu, Nov 7, 19, 00:00, 5 Years ago
;