剑道网格中的子项目

Child items in kendo grid

本文关键字:子项目 网格      更新时间:2023-09-26

如何在一列中绑定我的子数据?我想在同一栏同一行写"科技、经济、生活"。但我想我需要循环输入"分类"。我该怎么做,知道吗?

我的数据:

{
    "ParentId": "00000000-0000-0000-0000-000000000000",
    "Title": null,
    "UserGroupModel": null,
    "EntityAccessData": [
        {
            "EntityTitle": "User",
            "Access": {
                "Id": "59d0c6f7-8f93-497a-854d-bdd4a42ade94",
                "Title": "Can Delete"
            },
            "Category": [
                {
                    "Id": "00000000-0000-0000-0000-000000000000",
                    "Title": "Technology"
                },
                {
                    "Id": "00000000-0000-0000-0000-000000000000",
                    "Title": "Economy"
                },
                {
                    "Id": "00000000-0000-0000-0000-000000000000",
                    "Title": "Life"
                }
            ],
            "HasAccess": true
        },
        {
            "EntityTitle": "UserGroup",
            "Access": {
                "Id": "7c65be44-11b0-4cf4-9104-0ad999e7e280",
                "Title": "Can Edit"
            },
            "Category": [
                {
                    "Id": "00000000-0000-0000-0000-000000000000",
                    "Title": "Technology"
                },
                {
                    "Id": "00000000-0000-0000-0000-000000000000",
                    "Title": "Economy"
                },
                {
                    "Id": "00000000-0000-0000-0000-000000000000",
                    "Title": "Life"
                }
            ],
            "HasAccess": true
        }
    ]
}

我的脚本:

 $("#grid").kendoGrid({
        dataSource: {
            type: "json",
            transport: {
                read: "/getData" },
            schema: {
                data: "EntityAccessData"
            },
                group: [{
                field: "EntityTitle"
            }],
        },
        columns: [
        {
            field: "Access.Id",
            title: "ID"
        },
        {
            field: "Access.Title",
            title: "Access title"
        },
        {
            field: "HasAccess",
            title: "has access"
        },
        {
            field: "Category.Title", // ***wrong***
            title: "Category"
        },
        ]
    });

定义schema如下:

schema: {
    data : "EntityAccessData",
    model: {
        CategoryTitle: function () {
            var category = [];
            $.each(this.Category, function(idx, elem) {
                category.push(elem.Title);
            });
            return category.join(",");
        }
    }
},

我添加了一个额外的字段CategoryTitle,这是加入Category数组的Title的结果,然后将column定义为:

{
    field: "CategoryTitle()",
    title: "Category"
}