为什么jsTree open_all()对我不起作用? [英] Why doesn't jsTree open_all() work for me?

查看:533
本文介绍了为什么jsTree open_all()对我不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天开始使用jQuery和jsTree插件,并通过对Servlet的AJAX调用使其成功加载树.现在,我想让树在加载后打开所有节点,因此我向ajax属性添加了成功函数.但是,我似乎无法使open_all()方法正常工作.我对使用jQuery非常陌生,所以我猜这很简单,我做错了.

Started playing around with jQuery and the jsTree plugin yesterday, and have it successfully loading the tree with an AJAX call to a servlet. Now, I would like to have the tree open all the nodes after loading so I added a success function to the ajax attribute. However, I cannot seem to get the open_all() method to work properly. I'm very new to working with jQuery so I'm guessing it's something simple that I'm doing wrong.

Firebug没有显示任何错误,可以排除方法名称错误的愚蠢错误.我检查了文档,并根据阅读内容正确地完成了所有工作.该树正在正确加载,但在页面加载后未打开所有节点.

Firebug isn't showing any errors which rules out the dumb error of mistyped method name. I checked the documentation and I think I'm doing everything correctly according to what I read. The tree is loading correctly, but not opening all the nodes after the page loads.

我正在Firefox 3.6.8上使用jQuery 1.4.2和jsTree 1.0rc2.

I'm using jQuery 1.4.2 and jsTree 1.0rc2 on Firefox 3.6.8.

这是我用来加载树并尝试打开树中所有节点的代码:

Here's the code I'm using to load the tree and attempt to open all the nodes in the tree:

// Create the tree object
$("td#modelXML").jstree({
    core : { "animation" : 0 },
    //xml_data : {"data" : "" + xml, "xsl" : "nest"},
    xml_data : {"ajax" : 
                    {"url" : "servlet/GetModelHierarchy", 
                    "type" : "post", "data" : { modelId : "" + modelId} }, 
                    "xsl" : "nest",
                    "success" : function(){
                                $(this).open_all(-1);
                                }
    },
    themes : {"theme" : "classic", "dots" : true, "icons" : true},
    types : { 
        "types" : {
            "category" : {
                "valid_children" : ["factor"]
            },
            "factor" : {
                "valid_children" : ["level"]
            },
            "level" : {
                "valid_children" : "none",
                "icon" : {
                    "image" : "${request.contextPath}/jsTree/file.png"
                }
            }
        }
    },
    plugins : ["themes", "types", "xml_data"]
});

推荐答案

您必须加入事件,然后调用open_all.

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

在使用.jstree({...})初始化树之前,请执行上述操作.

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

这篇关于为什么jsTree open_all()对我不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆