延迟加载与jsTree [英] Lazy loading with jsTree

查看:1751
本文介绍了延迟加载与jsTree的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图动态加载JTree的节点时,会被扩展。小的文件,我发现是此页面

I am trying to dynamically load the nodes of a jtree when they are expanded. The little documentation I found is at the end of this page.

我找到了一些解决方案,打造节点一个个像<一环href="http://stackoverflow.com/questions/14952653/programatically-expanding-nodes-in-jstree-with-ajax-load">this 之一。我还没有尝试过,但在文档页面找我有jstree应该通过节点循环照顾的感觉。

I found some solutions that create the nodes one by one with a loop like this one. I have not tried it, but looking at the documentation page I have the feeling that jstree should take care of cycling through the nodes.

我发现,使用插件许多解决方案:json_data] ,而插件文档页面没有提到插件都没有。那是一个老的插件,现在不再需要了?

I found many solutions that use plugins: ["json_data"], but the plugins documentation page doesn't mention that plugin at all. Is that an old plugin that is not required anymore?

我的当前实现使用这种code加载整个树一炮打响:

My current implementation uses this code to load the whole tree in one shot:

$.ajax({
    var pn = $('#project_number').val();
    url : "bomtree?part=" + pn,
    success : function(tree_content) {
        var data = $.parseJSON(tree_content);
        var config = {
            'core' : {
                'data' : data
            }
        };
        $('#bom_tree').jstree(config);
    }
});

我修改了code这样的文档页面上:

I modified the code on the documentation page like this:

$(function() {
    var pn = $('#project_number').val();
    $('#tree').jstree({
        'core' : {
            'data' : {
                'url' : function(node) {
                    return '/doc/test2';
                },
                'data' : function(node) {
                    return {
                        'part' : node.id === '#' ? pn : node.id
                    };
                }
            }
        }
    });
});

同样的JSON文本与第一code工作,现在与第二。该文件说,的格式保持一致上述,所以我并没有改变它。

The same json text works with the first code, now with the second. The documentation says The format remains the same as the above, so I didn't change it.

我试图也返回相同的数据的例子中,这样的:

I tried also returning the same data as in the example, this:

[
       { "id" : "ajson1", "parent" : "#", "text" : "Simple root node" },
       { "id" : "ajson2", "parent" : "#", "text" : "Root node 2" },
       { "id" : "ajson3", "parent" : "ajson2", "text" : "Child 1" },
       { "id" : "ajson4", "parent" : "ajson2", "text" : "Child 2" },
]

但结果是一样的:jQuery的抛出一个Sizzle.error在下面一行:

But the result is the same: jquery throws a Sizzle.error at the following line:

Sizzle.error = function( msg ) {
    throw new Error( "Syntax error, unrecognized expression: " + msg );
};

其中,信息的内容是由服务器返回的JSON数据。

Where the content of msg is the json data returned by the server.

怎么了?

推荐答案

当使用AJAX集儿童为布尔true和jsTree将渲染节点关闭,当用户打开它进行额外要求的节点。这是来自 jstree 文档,并能达到您的要求。

"When using AJAX set children to boolean true and jsTree will render the node as closed and make an additional request for that node when the user opens it.", this is from jstree document and it could achieve your requirement.

这篇关于延迟加载与jsTree的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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