JsTree 返回“无效的 JSON”错误
我正在尝试制作一个 Jstree,其代码如下:
$(function () {
$("#groups")
.jstree({
"plugins" : [ "themes", "json_data", "ui", "crrm", "cookies", "dnd", "search", "types", "contextmenu" ],
"json_data" : {
"ajax" : {
"url" : base_url+"/json",
"data" : function (n) {
return { id : n.attr ? n.attr("id") : 0 };
},
error: function(e,b,d){alert(d);}
}
},
"types" : {
"max_depth" : -2,
"max_children" : -2,
"valid_children" : [ "drive" ],
"types" : {
"default" : {
"valid_children" : "none",
"icon" : {
"image" : "./file.png"
}
},
"folder" : {
"valid_children" : [ "default", "folder" ],
"icon" : {
"image" : "./folder.png"
}
}
}
},
"ui" : {
"initially_select" : [ "node_4" ]
},
"core" : {
"initially_open" : [ "node_2" , "node_3" ]
}
});
});
这是我从 Ajax 调用返回的 Json
[
{
"data" : "Genral ",
"attr" : {
"id" : "8"
},
"state" : "open",
"children" : [
{
"data" : "onec ",
"attr" : {
"id" : "16"
},
"state" : "close"
},
{
"data" : "onec2",
"attr" : {
"id" : "21"
},
"state" : "close"
}
]
},
{
"data" : "Stuff ",
"attr" : {
"id" : "9"
},
"state" : "open",
"children" : [
{
"data" : "one9 ",
"attr" : {
"id" : "23"
},
"state" : "close"
},
{
"data" : "bababa ",
"attr" : {
"id" : "24"
},
"state" : "close"
}
]
}
]
我收到一条错误消息“无效的 JSON:....”,我该如何解决这个问题?
谢谢。
I'm trying to make a Jstree, the code for it is the following:
$(function () {
$("#groups")
.jstree({
"plugins" : [ "themes", "json_data", "ui", "crrm", "cookies", "dnd", "search", "types", "contextmenu" ],
"json_data" : {
"ajax" : {
"url" : base_url+"/json",
"data" : function (n) {
return { id : n.attr ? n.attr("id") : 0 };
},
error: function(e,b,d){alert(d);}
}
},
"types" : {
"max_depth" : -2,
"max_children" : -2,
"valid_children" : [ "drive" ],
"types" : {
"default" : {
"valid_children" : "none",
"icon" : {
"image" : "./file.png"
}
},
"folder" : {
"valid_children" : [ "default", "folder" ],
"icon" : {
"image" : "./folder.png"
}
}
}
},
"ui" : {
"initially_select" : [ "node_4" ]
},
"core" : {
"initially_open" : [ "node_2" , "node_3" ]
}
});
});
This is the Json I get back from the Ajax call
[
{
"data" : "Genral ",
"attr" : {
"id" : "8"
},
"state" : "open",
"children" : [
{
"data" : "onec ",
"attr" : {
"id" : "16"
},
"state" : "close"
},
{
"data" : "onec2",
"attr" : {
"id" : "21"
},
"state" : "close"
}
]
},
{
"data" : "Stuff ",
"attr" : {
"id" : "9"
},
"state" : "open",
"children" : [
{
"data" : "one9 ",
"attr" : {
"id" : "23"
},
"state" : "close"
},
{
"data" : "bababa ",
"attr" : {
"id" : "24"
},
"state" : "close"
}
]
}
]
I get an Error saying 'Invalid JSON:....', how do I solve this?
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
返回的 JSON 有效。如果我猜测 - 也许你需要指定类型。例如:
The JSON returned is valid. If i were to take a guess - maybe you need to specify the type. EG:
我想 json_data 应该是
jQuery.ajax
调用:
I guess json_data rather needs to be an
jQuery.ajax
call: