将Odata绑定到KendoUI数据源以与Kendo Grid一起使用

时间:2013-11-28 00:46:57

标签: kendo-ui odata

我试图将剑道数据源首次绑定到odata源,而没有太多运气。我找到了一个示例产品,允许对odata控制器进行版本控制,看起来非常有用。 odata输出看起来像

{
"d": {
    "__metadata": {
        "id": "http://localhost:11232/versionbyroute/v1/Products(7)",
        "uri": "http://localhost:11232/versionbyroute/v1/Products(7)",
        "type": "ODataVersioningSample.V1.ViewModels.Product",
        "actions": {
            "http://localhost:11232/versionbyroute/v1/$metadata#Container.Product": [
                {
                    "title": "Product",
                    "target": "http://localhost:11232/versionbyroute/v1/Products(7)/Product"
                }
            ]
        }
    },
    "ID": 7,
    "Name": "MS-DOS 3.0 (OEM)",
    "ReleaseDate": null,
    "SupportedUntil": null
}

}

现在有了剑道,我不太清楚我是如何获得ID& amp;到目前为止的名字

   var datasource = new kendo.data.DataSource({
        type: "odata",
        transport: {
            read: {
                beforeSend: function (req) {
                    req.setRequestHeader('Accept', 'application/json;odata=verbose');
                },
                url: "http://localhost:11232/versionbyroute/v1/Products(7)",

            }
        },
        schema: {
            model: {
                fields: {
                    Name: { type: "string" }

                }
            }
        },
        pageSize: 20,
        serverPaging: true,
        serverFiltering: true,
        serverSorting: true
    });


    $("#grid").kendoGrid({
        height: 430,
        sortable: true,
        dataSource: datasource,
        columns: [{ field: 'Name', title: 'Name' }]


    });

我觉得我很接近,但我认为我设置架构的方式有问题吗?任何人都可以指出我正确的方向。

修改

如果其他人在同一条船上

   $("#grid").kendoGrid({
        height: 430,
        sortable: true,
        dataSource: {
            type: "odata",
            transport: {
                read: {
                    beforeSend: function (req) {
                                    req.setRequestHeader('Accept', 'application/json;odata=verbose');
                                },
                    url: "http://localhost:11232/versionbyroute/v1/Products",
                    dataType: "json"
                }
            },
            pageSize: 20,
            serverPaging: true,
            serverFiltering: true,
            serverSorting: true,
        },
        filterable: true,
        pageable: true,
        columns: [{ field: 'Name', title: 'Name' }]
    });

1 个答案:

答案 0 :(得分:1)

作者回答:

如果其他人在同一条船上

   $("#grid").kendoGrid({
        height: 430,
        sortable: true,
        dataSource: {
            type: "odata",
            transport: {
                read: {
                    beforeSend: function (req) {
                                    req.setRequestHeader('Accept', 'application/json;odata=verbose');
                                },
                    url: "http://localhost:11232/versionbyroute/v1/Products",
                    dataType: "json"
                }
            },
            pageSize: 20,
            serverPaging: true,
            serverFiltering: true,
            serverSorting: true,
        },
        filterable: true,
        pageable: true,
        columns: [{ field: 'Name', title: 'Name' }]
    });