这是我输出到控制台的json结构:
0:
ApplicationName: null
ApplicationsId: "024e5e4b-9afd-44af-be33-8cab3eb6ce8c"
CreatedOn: "2019-04-03T23:20:30.063584"
Path: ""
children: [{…}]
id: "a97620e2-690c-4c5d-9a53-4c4ef713156e"
parent: "#"
text: "main 1"
__proto__: Object
1:
ApplicationName: null
ApplicationsId: "024e5e4b-9afd-44af-be33-8cab3eb6ce8c"
CreatedOn: "2019-04-03T23:20:36.0979761"
Path: ""
children: []
id: "993f86eb-df13-40ea-a519-263bb844ee43"
parent: "#"
text: "main 2"
__proto__: Object
2:
ApplicationName: null
ApplicationsId: "024e5e4b-9afd-44af-be33-8cab3eb6ce8c"
CreatedOn: "2019-04-03T23:20:36.1190942"
Path: ""
children: [{…}]
id: "fe0aeaad-468d-4482-856a-b87273df4b80"
parent: "#"
text: "main 3"
__proto__: Object
3:
ApplicationName: null
ApplicationsId: "024e5e4b-9afd-44af-be33-8cab3eb6ce8c"
CreatedOn: "2019-04-03T23:20:36.1238693"
Path: ""
children: [{…}]
id: "279931ad-e89c-4056-b0bc-7be41339baba"
parent: "#"
text: "main 4"
__proto__: Object
我正在尝试将其加载到jstree中,但我不断收到错误消息:
无法读取parse_flat中未定义的属性“ id”
这是我现在声明我的jstree的方式:
$("#tree").jstree({
'core': {
'data': {
"url": "@Url.Action("DisplayChildren", @ViewContext.RouteData.Values["controller"].ToString())",
"dataType":"json"
}
}
});
这是被称为的控制器:
[HttpGet]
[Route("Repositories/Repositories/DisplayChildren")]
public JsonResult DisplayChildren()
{
var output = repositoriesData.GetChildren("");
return Json(output);
}
我想念什么吗?我已经更改了某些对象的名称,并且子对象都具有一个现有的父代。
编辑:
我添加了一个JSON.stringify以查看是否可以转换输出。错误消失了,但屏幕上没有任何显示。控制台显示如下:
[{"id":"a97620e2-690c-4c5d-9a53-4c4ef713156e","parent":"#","text":"main 1","ApplicationName":null,"ApplicationsId":"024e5e4b-9afd-44af-be33-8cab3eb6ce8c","Path":"","CreatedOn":"2019-04-03T23:20:30.063584","children":[{"id":"f3e0a4aa-f466-455d-b102-c79e62775e63","parent":"a97620e2-690c-4c5d-9a53-4c4ef713156e","text":"main 1 - sub 1","ApplicationName":null,"ApplicationsId":"024e5e4b-9afd-44af-be33-8cab3eb6ce8c","Path":"","CreatedOn":"2019-04-03T23:20:36.1176032","children":[]}]},{"id":"993f86eb-df13-40ea-a519-263bb844ee43","parent":"#","text":"main 2","ApplicationName":null,"ApplicationsId":"024e5e4b-9afd-44af-be33-8cab3eb6ce8c","Path":"","CreatedOn":"2019-04-03T23:20:36.0979761","children":[]},{"id":"fe0aeaad-468d-4482-856a-b87273df4b80","parent":"#","text":"main 3","ApplicationName":null,"ApplicationsId":"024e5e4b-9afd-44af-be33-8cab3eb6ce8c","Path":"","CreatedOn":"2019-04-03T23:20:36.1190942","children":[{"id":"aa230395-0731-48ff-824d-304237c34034","parent":"fe0aeaad-468d-4482-856a-b87273df4b80","text":"main 3 - sub 1","ApplicationName":null,"ApplicationsId":"024e5e4b-9afd-44af-be33-8cab3eb6ce8c","Path":"","CreatedOn":"2019-04-03T23:20:36.1206852","children":[{"id":"0b16f5f2-032a-43d6-8b24-ac4368d86c5e","parent":"aa230395-0731-48ff-824d-304237c34034","text":"main 3 - sub 1 - subsub 1","ApplicationName":null,"ApplicationsId":"024e5e4b-9afd-44af-be33-8cab3eb6ce8c","Path":"","CreatedOn":"2019-04-03T23:20:36.1223118","children":[]}]}]},{"id":"279931ad-e89c-4056-b0bc-7be41339baba","parent":"#","text":"main 4","ApplicationName":null,"ApplicationsId":"024e5e4b-9afd-44af-be33-8cab3eb6ce8c","Path":"","CreatedOn":"2019-04-03T23:20:36.1238693","children":[{"id":"95a31a4b-6bf1-47b3-91e0-2ffddd4deec1","parent":"279931ad-e89c-4056-b0bc-7be41339baba","text":"main 4 - sub 1","ApplicationName":null,"ApplicationsId":"024e5e4b-9afd-44af-be33-8cab3eb6ce8c","Path":"","CreatedOn":"2019-04-03T23:20:36.1255852","children":[]}]}]
答案 0 :(得分:0)
ajax调用没有任何问题,否则您将不会遇到双重错误。另外,您不是在声明jstree,而是在创建一个具有树ID的对象,并使用jstree函数创建JSON来捕获结果。
1)您的ID类型为字符串而不是字符(parse_flat)(无法读取属性“ id”)。 2)您的ApplicationName为null(未定义)。