繁体   English   中英

从jstree中的外部json文件加载数据

[英]load data from external json file in jstree

我想将json数据从外部文件传递到jstree对象。 我有以下代码段,但没有用

<script>
            $.jstree.defaults.core.themes.responsive = true;
$('#frmt').jstree({
    plugins: ["checkbox", "types"],
    "json_data":{
    "ajax" : {
        "url" : "D:\p\web\nodes.json"  // the URL to fetch the data. Use relative url if required
     }
},
       "types": {
        "file": {
            "icon": "jstree-file"
        }
    }
});
</script>

我的nodes.json文件

[
 {
  "id": "ajson1",
  "parent": "#",
  "text": "Simple root node"
}, 
{
  "id": "ajson2",
  "parent": "#",
  "text": "Root node 2"
}, {
  "id": "ajson3",
  "parent": "ajson2",
  "text": "Child 1"
}, {
  "id": "ajson4",
  "parent": "ajson2",
  "text": "Child 2"
}
]

当我在javascript中手动插入此数据时,它可以正常工作,但是当我在那时分配node.json外部文件的路径时,它不起作用

您正在使用哪个版本的jstree? 当前版本是3.3.1。 较旧的版本有一个名为json_data的插件,您需要在插件列表中包括“ json_data”。 如果使用最新版本,则无需使用“ json_data”,只需使用“ url”即可。 请参见下面的示例:

$('#tree').jstree({
    'core' : {
        'data' : {
            'url' : function (node) {
                return node.id === '#' ? 'ajax_roots.json' : 'ajax_children.json';
             },
            'data' : function (node) {
                return { 'id' : node.id };
            }
         }
    });

希望能有所帮助。

暂无
暂无

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

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