【问题标题】:Creating a JSTree node on a specific position in the tree在树中的特定位置创建 JSTree 节点
【发布时间】:2013-12-17 13:34:48
【问题描述】:

我正在尝试更新 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')));                        
                }
            });

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

我需要从 getJSONData() 函数中为每个孩子设置数据,而不是不工作的行。它返回的数据格式与最初加载 jsonData 时使用的格式相同 - 一个 JSON 对象。

请问我该怎么做?

【问题讨论】:

    标签: javascript jquery ajax jstree


    【解决方案1】:

    我已经设法实现了我想要的,但这似乎是一个 hack:

    .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]);
                    }
                });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-14
      相关资源
      最近更新 更多