jsTree通过ajax加载孩子

Efr*_*rin 12 javascript ajax jquery jstree

下面发布的代码通过ajax请求加载我的树的根元素.我的树非常大,所以我无法一次加载所有项目所以我需要通过请求孩子为特定ID加载元素.

如何通过单击节点按ajax加载元素?

  $('#jstree_demo_div').jstree({
            "plugins" : ["wholerow", "checkbox"],
            'core' : {
                'data' : {
                    'url' : function(node) {
                        return "/" + site + "/places/api/tree/list/";
                    }
                },
            }

        });
Run Code Online (Sandbox Code Playgroud)

json样本的一部分

[
   {
      "text":"zachodniopomorskie",
      "state":"closed",
      "id":212353,
   },
Run Code Online (Sandbox Code Playgroud)

固定版本:

 $('#jstree_demo_div').jstree({
            "plugins" : ["wholerow", "checkbox"],
            'core' : {
                'data' : {
                    'url' : "/" + site + "/places/api/tree/list/",
                    'data' : function(node) {
                        return {
                            'id' : node.id
                        };
                    }
                },
            }
        })
Run Code Online (Sandbox Code Playgroud)

我的问题的解决方案是,如果我想通过ajax请求返回子项,我需要返回包含以下内容的json文件:

"children:" true
Run Code Online (Sandbox Code Playgroud)

Efr*_*rin 5

 $('#jstree_demo_div').jstree({
            "plugins" : ["wholerow", "checkbox"],
            'core' : {
                'data' : {
                    'url' : "/" + site + "/places/api/tree/list/",
                    'data' : function(node) {
                        return {
                            'id' : node.id
                        };
                    }
                },
            }
        })
Run Code Online (Sandbox Code Playgroud)

我的问题的解决方案是,如果我想通过 ajax 请求返回子级,我需要返回包含以下内容的 json 文件:

"children:" true
Run Code Online (Sandbox Code Playgroud)