0

如何将我的子数据绑定在一列中?我想在同一列和同一行中写“技术、经济、生活”。但我认为我需要循环进入“类别”。我该怎么做,有什么想法吗?

我的数据:

{
    "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"
        },
        ]

    });
4

1 回答 1

1

定义schema如下:

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

},

我在其中添加了一个附加字段,该字段CategoryTitle是加入数组的结果TitleCategory然后将其定义column为:

{
    field: "CategoryTitle()",
    title: "Category"
}
于 2013-02-27T23:05:45.953 回答