open_all on loaded event not firing

754 views
Skip to first unread message

Brett Matthews

unread,
Feb 12, 2014, 6:48:46 PM2/12/14
to jst...@googlegroups.com
Could someone please explain to me why my tree is not expanding when the loading has finished?

The on button click will expand the tree, but its as if the event loaded is fired earlier then expected.

I have tried moving the event before and after the $('#jstree').jstree() call, as well as trying the ready event.

Temporary solution I will add the class jstree-open to <li> elements, but I don't particularly like this.


<!DOCTYPE html>
<html>
<head>
 
<meta charset="utf-8">
 
<title>jsTree test</title>
 
<!-- 2 load the theme CSS file -->
 
<link rel="stylesheet" href="dist/themes/default/style.min.css" />
</head>
<body>
 
<!-- 3 setup a container element -->
 
<div id="jstree" class="demo">
   
<!-- in this example the tree is populated from inline HTML -->
   
<ul>
     
<li>Root node 1
       
<ul>
         
<li id="child_node_1">Child node 1</li>
         
<li>Child node 2</li>
       
</ul>
     
</li>
     
<li>Root node 2</li>
   
</ul>
 
</div>
 
<button>demo button</button>

 
<!-- 4 include the jQuery library -->
 
<script src="dist/libs/jquery.js"></script>
 
<!-- 5 include the minified jstree source -->
 
<script src="dist/jstree.min.js"></script>
 
<script>
  $
(function () {
   
// 6 create an instance when the DOM is ready
    $
('#jstree').on("loaded.jstree", function (e, data) {
         $
('#jstree').jstree('open_all');
     
});
   
    $
('#jstree').jstree();
   
// 7 bind to events triggered on the tree
    $
('#jstree').on("changed.jstree", function (e, data) {
      console
.log(data.selected);
   
});

   
// 8 interact with the tree - either way is OK
    $
('button').on('click', function () {
       $
('#jstree').jstree('open_all');
   
});
 
});
 
</script>
</body>
</html>


Ivan Bozhanov

unread,
Feb 13, 2014, 1:17:42 AM2/13/14
to jst...@googlegroups.com
instead of loaded.jstree use ready.jstree, and inside you could use data.instance.open_all()
Message has been deleted

Brett Matthews

unread,
Feb 13, 2014, 6:24:53 PM2/13/14
to jst...@googlegroups.com
Thank you this is what was needed.

data.instance.open_all()




Reply all
Reply to author
Forward
0 new messages