Kendo Tree View显示没有关于Controller获得JSON结果的记录



我正在研究Kendo Treeview Control,并尝试在网格中显示树结构。我正在从控制器操作方法中获取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);
    }

以下是我从操作方法中获得的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}]}

任何帮助得到高度赞赏

预先感谢

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

schema: {
    data: "Data"

您必须告诉dataSource json中的哪个属性。

相关内容

  • 没有找到相关文章

最新更新