Why doesn't jsTree open_all() work for me?

家住魔仙堡 提交于 2019-11-30 06:10:15

You have to hook into the events, and then call open_all.

To have all nodes open on load, use:

    var tree = $("#id-or-selector-for-my-tree-element");
    tree.bind("loaded.jstree", function (event, data) {
        tree.jstree("open_all");
    });

Do the above, before you initialize the tree with .jstree({...}).

If you refresh it, then to have all nodes open again, you have to use:

    tree.bind("refresh.jstree", function (event, data) {
        tree.jstree("open_all");
    });

Yes, this is an old question, but with no accepted answer and having the only answer not being useful to me, here's my answer which I now use:

var tree = $("td#modelXML")
    .bind("loaded.jstree", function (e, data) {
        data.inst.open_all(-1); // -1 opens all nodes in the container
    })
    .jstree({ /* your jsTree options as normal */ });

The key point here is that data.inst is your jsTree, and is the only reference you will have available because tree won't have a value until .jstree({ finishes. Since loaded.jstree is called within the .jstree({ call, the result will not yet exist. See?

I was completely unable to get it to work either with tree.jstree('open_all') or data.inst.open_all(-1) - in the end I had to use data.instance.open_all() - notice the change from inst to instance, and open_all(-1) to just open_all() - both of those seem to be required with jQuery 1.11 and jstree 3.0.0. My final code block looks like this:

$(document).ready(function() {
    var tree = $('#jstree');
    tree.bind('loaded.jstree', function(event, data) {
        data.instance.open_all();   
    });
    tree.jstree({});
});
guest

Try this!

$("td#modelXML").jstree("open_all","#nodeID");
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!