How do I open all nodes in jquery Jstree?

前端 未结 9 1750
感情败类
感情败类 2021-02-05 00:07

I am using the following code:

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

With the following html:

相关标签:
9条回答
  • 2021-02-05 00:58

    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');
      });
    
    0 讨论(0)
  • 2021-02-05 01:00

    use simple code

    $(".jstree").jstree().on('loaded.jstree', function () {
         $(".jstree").jstree('open_all');
    })
    
    0 讨论(0)
  • 2021-02-05 01:03

    I tried all the answers here and they didn't work with jsTree (v3.3.4). What worked is the load_node.jstree event:

        .on( 'load_node.jstree', function () {
          jstree.jstree( "open_all" );
        } )
    
    0 讨论(0)
提交回复
热议问题