JSTree无法读取未定义的属性“id”

问题描述 投票:1回答:1

这是我输出到控制台的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);
}

我错过了什么吗?我已经更改了一些对象的名称,并且子对象都有一个现有的parentid。

编辑:

我添加了一个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":[]}]}]
javascript jquery asp.net asp.net-mvc jstree
1个回答
0
投票

你的ajax调用没有任何问题,否则你就不会得到双重错误。此外,您没有声明jstree,您正在创建一个id为tree的对象,并使用jstree函数创建JSON来捕获结果。

1)你有一个字符串而不是一个平面(parse_flat)作为你的id类型(不能读取属性'id')。 2)您的ApplicationName为null(未定义)。

© www.soinside.com 2019 - 2024. All rights reserved.