【问题标题】:Binding Odata to a KendoUI datasource for use with Kendo Grid将 Odata 绑定到 KendoUI 数据源以与 Kendo Grid 一起使用
【发布时间】:2013-11-28 00:46:56
【问题描述】:

我第一次尝试将 kendo 数据源绑定到 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
}

}

现在有了 Kendo,我不太清楚我现在是如何获得 ID 和姓名的访问权限

   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' }]
    });

【问题讨论】:

  • 很高兴您找到了解决问题的方法。但是,最好通过实际使用下面的“发布您的答案”部分来回答您自己的问题(即不要用答案编辑您的问题)。这样,它不再被列为未答复。谢谢。

标签: kendo-ui odata


【解决方案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' }]
    });

【讨论】:

  • 这对我有帮助。实际上,如果您解释了解决方案会更好,但它可以作为一个插件,所以...谢谢!
猜你喜欢
  • 2015-06-16
  • 2015-06-14
  • 2013-03-15
  • 1970-01-01
  • 2014-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-11
相关资源
最近更新 更多