我正在尝试在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对象)返回数据。
我该怎么做?
我已经设法实现了想要的目标,但看起来像一个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]);
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句