我正在尝试在 open_node.jstree
事件上更新 JSTree 结构。它应该填充打开的父级的子级。
treeContent.jstree({
"json_data": {"data": jsonData},
"progressive_render": "true",
"plugins": ["themes", "json_data", "ui", "checkbox"]
})
在这部分中,jsonData
是从 Ajax 调用接收到的加载到树中的实际数据。
我想像这样绑定(bind)一个事件:
.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() 函数为每个 child 设置数据,而不是那行不起作用。它以与首先加载 jsonData
时使用的格式相同的格式返回数据 - JSON 对象。
请问我该怎么做?
最佳答案
我已经设法实现了我想要的,但它似乎是一个 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]);
}
});
关于javascript - 在树中的特定位置创建 JSTree 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20635595/