jsTree Open a branch

后端 未结 8 743
长发绾君心
长发绾君心 2021-02-02 11:07

I am using the JQuery plugin jsTree, http://www.jstree.com/ I am able to expand the whole tree with the following method:

$(\"#tree\").jstree(\"open_all\");
         


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-02 11:44

    Try this code to open node till nth Level

    $("#myTree").jstree({options}).bind('loaded.jstree', function (e, data) {
        /** 
         * Open nodes on load (until x'th level) 
         */
        var depth = 3;
        data.inst.get_container().find('li').each(function (i) {
            if (data.inst.get_path($(this)).length <= depth) {
                data.inst.open_node($(this));
            }
        });
    });
    

提交回复
热议问题