在树中的特定位置创建JSTree节点

时间:2013-12-17 13:34:49

标签: javascript jquery ajax jstree

我正在尝试更新open_node.jstree事件上的JSTree结构。它应该填充已打开的父项的子项。

treeContent.jstree({
        "json_data": {"data": jsonData},
        "progressive_render": "true",
        "plugins": ["themes", "json_data", "ui", "checkbox"]
    })

在这部分中,jsonData是从Ajax调用中收到的树中加载的实际数据。 我想绑定一个像这样的事件:

.bind("open_node.jstree", function (event, data) {
                children = data.inst._get_children(data.rslt.obj);
                for (i = 0; i < children.length; i++) {
                    //this doesn't work
                    treeContent.jstree("create", children[i], "inside", getJSONData(children[i].getAttribute('path')));                        
                }
            });

By不起作用我的意思是从getJSONData接收到正确的数据,但不改变子元素。

我需要从getJSONData()函数为每个子节点设置数据,而不是不起作用的行。它以与首先加载jsonData时使用的格式相同的方式返回数据 - 一个JSON对象。

我该怎么办呢?

1 个答案:

答案 0 :(得分:1)

我已经成功实现了我想要的东西,但它看起来像是一个黑客:

.bind("open_node.jstree", function (event, data) {
                children = data.inst._get_children(data.rslt.obj);
                for(var i=0; i<children.length; i++){
                    data.inst.create_node(data.rslt.obj, "inside", getJSONData(children[i].getAttribute('path')));
                    data.inst.delete_node(children[i]);
                }
            });