[英]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.