【发布时间】:2011-10-27 10:01:11
【问题描述】:
我有一个使用 json 数据格式的 jsTree。 加载根节点集就可以了。
我的问题是如何将子节点附加到被点击的父节点。
任何帮助将不胜感激。
谢谢!
$("#tree-cat1")
.bind("open_node.jstree", function (event, data) {
console.log(data.rslt.obj.attr("id"));
//eval(loadChild());
//at this point i need to append the result of loadChild() to the tree under the relevant node
})
.jstree({
"json_data": {
"data": eval(loadRoot())
},
"themes": {"theme": "classic","dots": true,"icons": true},
"plugins": ["themes", "json_data", "ui"]
})
function loadRoot() {
return "[{'data':'A node','state':'closed','attr':{'id':'A'}}]";
}
function loadChild() {
return "[{'data':'A1 node','attr':{'id':'A1'}}]";
}
【问题讨论】:
-
是否要在每次打开节点时添加子节点?为什么你不使用 'children' 属性在树初始化时附加项目
-
每次节点扩展时,我都会运行 oracle 查询来获取数据(全部在 javascript 中)。返回到 js 变量中的数据。然后我必须在树中的相关点用返回的数据填充树(根据代码示例)
标签: javascript jquery plugins jstree