0

我正在研究剑道 TreeView 控件并尝试在网格中显示树结构。我从控制器 Action Method 获取 json 数据,但控件总是显示一条错误消息“没有要显示的记录”,谁能帮我找出我的错误。

下面是我的javascript代码。

<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.913/styles/kendo.common-material.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.913/styles/kendo.material.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.913/styles/kendo.material.mobile.min.css" />

<script src="https://kendo.cdn.telerik.com/2017.3.913/js/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2017.3.913/js/kendo.all.min.js"></script>
<script type="text/javascript">

    $(document).ready(function () {
        var modelId = $("#hdnModelId").val();
        var dataSource = new kendo.data.TreeListDataSource({
            transport: {
                read: {
                    url: "/EntityData/GetEntities",
                    dataType: "json",
                    data: { modelId: modelId }
                }
            },
            schema: {
                model: {
                    id: "EntityId",
                    parentId: "ParentEntityId",
                    fields:
                        {
                            Name: { field: "Name", type: "string" },
                            EntityId: { type: "number", editable: false, nullable: false },
                            ParentEntityId: { field: "ParentEntityId", nullable: true}
                        },
                }
            }
        });
        
        $("#treelist").kendoTreeList({
            dataSource: dataSource,
            columns: [{ field: "Name" }]
        });       
    });

    
</script>

.

下面是我的操作方法。

    [HttpGet]
    public ActionResult GetEntities(int modelId)
    {            
        var entities = metaDataService.GetEntitiesByModelId(modelId).ToList();
        return Json(new { Data = entities }, JsonRequestBehavior.AllowGet);
    }

下面是我从我的 Action Method 中获得的 Json 数据。

{"Data":[{"EntityId":1,"ApplicationId":2,"Name":"Car","Description":"This entity describes a car.!","IsPublished":true,"IsDeleted":false,"ParentEntityId":null,"HasChildren":false},{"EntityId":20,"ApplicationId":2,"Name":"Test 567","Description":"Test 567!","IsPublished":true,"IsDeleted":false,"ParentEntityId":null,"HasChildren":false},{"EntityId":21,"ApplicationId":2,"Name":"Test Tst Entity","Description":"Test Tst Entity1234","IsPublished":true,"IsDeleted":false,"ParentEntityId":1,"HasChildren":true},{"EntityId":23,"ApplicationId":2,"Name":"Test New Entity","Description":"Test New Entity","IsPublished":true,"IsDeleted":false,"ParentEntityId":null,"HasChildren":false},{"EntityId":46,"ApplicationId":2,"Name":"Kendo Entity Test","Description":"Kendo Entity Test","IsPublished":true,"IsDeleted":false,"ParentEntityId":null,"HasChildren":false},{"EntityId":63,"ApplicationId":2,"Name":"Test new Entity","Description":"Test New Entity","IsPublished":true,"IsDeleted":false,"ParentEntityId":20,"HasChildren":true}]}

非常感谢任何帮助

提前致谢

4

1 回答 1

0

尝试将此添加到您的架构中:

schema: {
    data: "Data"

您必须告诉 DataSource 数组是 json 中的哪个属性。

于 2017-10-06T11:27:25.700 回答