如何使用“jstree”将 json 变量附加为子节点jquery 插件 - 没有 ajax
我有一个使用 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'}}]";
}
I have a jsTree using the json data format.
Loading the root nodeset is fine.
My problem is how to append child nodes to the parent node that was clicked.
ANY help would be appreciated.
Thanks!
$("#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'}}]";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅此处的文档: jsTree docu
编辑
这是代码,您需要要将 url 更改为您的目的地,请尝试
html:
js:
旧部分
类似的事情将用子节点填充打开的节点(如果尚未完成):
see documentation here: jsTree docu
EDIT
here is the code, you need to change url to your destination, try it
html:
js:
OLD PART
something like that will populate opened node with children, if not already done: