Javascript jsTree通过ajax加载子级
下面发布的代码通过ajax请求加载我的树的根元素。 我的树非常大,所以我不能一次加载所有项目,所以我需要通过请求特定ID的子元素来加载元素 如何通过单击节点通过ajax加载元素Javascript jsTree通过ajax加载子级,javascript,jquery,ajax,jstree,Javascript,Jquery,Ajax,Jstree,下面发布的代码通过ajax请求加载我的树的根元素。 我的树非常大,所以我不能一次加载所有项目,所以我需要通过请求特定ID的子元素来加载元素 如何通过单击节点通过ajax加载元素 $('#jstree_demo_div').jstree({ "plugins" : ["wholerow", "checkbox"], 'core' : { 'data' : { 'url' :
$('#jstree_demo_div').jstree({
"plugins" : ["wholerow", "checkbox"],
'core' : {
'data' : {
'url' : function(node) {
return "/" + site + "/places/api/tree/list/";
}
},
}
});
json示例的一部分
[
{
"text":"zachodniopomorskie",
"state":"closed",
"id":212353,
},
固定版本:
$('#jstree_demo_div').jstree({
"plugins" : ["wholerow", "checkbox"],
'core' : {
'data' : {
'url' : "/" + site + "/places/api/tree/list/",
'data' : function(node) {
return {
'id' : node.id
};
}
},
}
})
$('#jstree_demo_div').jstree({
"plugins" : ["wholerow", "checkbox"],
'core' : {
'data' : {
'url' : "/" + site + "/places/api/tree/list/",
'data' : function(node) {
return {
'id' : node.id
};
}
},
}
})
我的问题的解决方案是,如果我想通过ajax请求返回子对象,我需要返回json文件,该文件包含:
"children:" true
"children:" true
试试这个:
$('#jstree_demo_div').jstree(options).bind("select_node.jstree",function(event, data){
//Load child node here
});//or "dbclick.jstree" instead of "select_node.jstree"
如果需要加载子节点,可以尝试使用
$("#jstree_demo_div").bind("select_node.jstree", function(e, data) {
$("#jstree_demo_div").jstree('open_node', data.node);
}
因此它将触发一个ajax加载触发器
我的问题的解决方案是,如果我想通过ajax请求返回子对象,我需要返回json文件,该文件包含:
"children:" true
"children:" true
我仍然不明白应该如何加载子节点。我应该在那里调用什么函数?我已经修好了。检查我的解决方案检查我在第1篇博文+1中的答案,以了解
“children”:true
。jstree很棒,但docu很烂。