从控制器获取json结果时,Kendo Tree View不显示任何记录

时间:2017-10-06 06:56:03

标签: kendo-ui kendo-grid kendo-treeview kendo-treelist

我正在研究kendo TreeView控件并尝试在网格中显示树结构。我从控制器操作方法获取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}]}

非常感谢任何帮助

提前致谢

1 个答案:

答案 0 :(得分:0)

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

schema: {
    data: "Data"

你必须告诉数据源你的json数组是哪个属性。