kendo-ui - 将 Odata 绑定(bind)到 KendoUI 数据源以与 Kendo Grid 一起使用

标签 kendo-ui odata

我第一次尝试将 kendo 数据源绑定(bind)到 odata 源,但运气不佳。我找到了一个示例产品,它允许对 odata Controller 进行版本控制,这看起来非常有用。 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' }]
    });

最佳答案

作者回答:

如果其他人在同一条船上

   $("#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 绑定(bind)到 KendoUI 数据源以与 Kendo Grid 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20255851/

相关文章:

javascript - 使用一些默认值在 Kendo Grid 中添加新行

asp.net-mvc - 如何在 Excel 中指定 API key 名称 - 只有在提供 Web API key 名称时才能指定 Web API key

odata - OData v4 不支持 Nullable<DateTime> 吗?

javascript - 如何禁用 Kendo UI NumericTextBox 上的点?

azure - 为什么我的 Azure Devops Pipeline 无法还原包?

javascript - 丢失过滤器菜单中的文本框值

c# - 尝试标记为 odata 时,可查询属性未在 mvc 4 web api 中编译

javascript - 网格初始化后的 Kendo 网格事件处理

c# - Entity Framework 6 - DataServiceContext 检测有变化

javascript - 如何以安全的方式读写 OData 调用? (比如不容易受到 CSRF 攻击?)