简体   繁体   English

jsTree v.3 延迟加载与 ajax 调用

[英]jsTree v.3 lazy loading with ajax call

I've been making a jstree lazy loading with ajax call, but i met a problem.我一直在使用 ajax 调用进行 jstree 延迟加载,但是我遇到了一个问题。

my code brings json data with 1 depth successfully.我的代码成功地带来了 1 个深度的 json 数据。 however when I click or select node, it doesn't bring its child.但是,当我单击或选择节点时,它不会带来它的子节点。 I dont know what my problem is.我不知道我的问题是什么。

this is my javascript code这是我的 javascript 代码

 $("#tree").jstree({ 'core' : { 'data' : { 'url' : function(node) { return'/url/getTree'; }, 'type' : 'GET', 'data' : function(node) { return { parentId : node.id ==="#" ? 0 : node.id, searchdepth : 1 } }, 'success' : function(data) { return data.list } }, 'check_callback':true, }, "plugins" : ["json_data"] });

and my result data is like this我的结果数据是这样的

 [{"id":"1","text":"node_1","data":{"selected":"N"},"children":[{"id":"3","text":"node_3","data":{"selected":"N"}},{"id":"2","text":"node_2","data":{"selected":"N"}}]}]

Your JSON document does not seem to be correct.您的 JSON 文档似乎不正确。 The document needs to contain exactly one array which contains only the children of the node you requested information for.该文件必须包含正好一个阵列包含您所需的信息为节点的孩子。

So using your example, when you request information for node with id 1 your json needs to look like this:因此,使用您的示例,当您请求 ID 为 1 的节点的信息时,您的 json 需要如下所示:

[
   {"id":"3","text":"node_3","data":{"selected":"N"}, "children":true/false},
   {"id":"2","text":"node_2","data":{"selected":"N"}, "children":true/false}
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM