【问题标题】:Kendoui DataSource odata $expand not workingKendoui DataSource odata $expand 不工作
【发布时间】:2013-07-20 01:34:49
【问题描述】:

我有一个绑定到指向 odata 服务的 kendoui 数据源的移动列表视图。我在数据源配置中有一个 $expand 提示来扩展“Claim”对象的“Patient”属性,但是查看 odata 查询的 url,kendoui 数据源没有在查询字符串中生成 $expand 代码。如何让 kendoui 数据源在查询字符串上生成正确的 $expand 指令?

OData query string genereated: http://localhost:1839/OData.svc/Claim?$callback=jQuery20207924230222124606_1374374358450&%24inlinecount=allpages&%24format=json&%24top=10

<script>
    $(function () {
        var app = new kendo.mobile.Application(document.body, {
            transition: 'slide'
        });

        OData.defaultHttpClient.enableJsonpCallback = true;


        var data = new kendo.data.DataSource({
            type: "odata", // specifies data protocol
            pageSize: 10,  // limits result set
            transport: {
                read: "http://localhost:1839/OData.svc/Claim",
                dataType: "json",
                data: {
                    $expand: "Patient"
                }
            },
            schema: {
                model: {id: "Id"},
                data: function (data) {
                    return data.d.results;
                },
                total: function (data) {
                    return data.d.__count;

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

        $("#lst").kendoMobileListView(
        {
            template: "<strong>${data.ClaimNumber}</strong><br/>",
            filterable: {
                field: "ClaimNumber",
                operator: "contains"
            },
            dataSource: data
        });
    });
</script>

【问题讨论】:

    标签: kendo-ui datasource odata


    【解决方案1】:

    我在传输/读取/url中添加了这个权利,而不是单独的数据:

        var dataSource = new kendo.data.HierarchicalDataSource({
            type: "odata",
            transport: {
                read: {
                    // See http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/ for OData URI conventions
                    // OData: ~/api/Users?$inlinecount=allpages&top=2
                    // OData: ~/api/Users?$inlinecount=allpages - includes odata.count
                    // OData: inline filtering: ~/api/Users?$filter=USERNAME eq 'asgro'
                    // to include hierarchical data, use the OData /api/UserGroups?$expand=USER
                    // To reduce the payload sice, the query ~/api/UserGroups will only include the USERGROUP entities, and not any navigation property content
    
    
                    url: "/api/UserGroups?$expand=USERS",
                    dataType: "json"                                // the default result type is JSONP, but WebAPI does not support JSONP
                },
    .
    .
    .
    

    【讨论】:

      【解决方案2】:

      数据和 $expand 属于读取对象。你的答案越来越接近了。

      var dataSource = new kendo.data.HierarchicalDataSource({
          type: "odata",
          transport: {
              read: {
                  // See http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/ for OData URI conventions
                  // OData: ~/api/Users?$inlinecount=allpages&top=2
                  // OData: ~/api/Users?$inlinecount=allpages - includes odata.count
                  // OData: inline filtering: ~/api/Users?$filter=USERNAME eq 'asgro'
                  // to include hierarchical data, use the OData /api/UserGroups?$expand=USER
                  // To reduce the payload sice, the query ~/api/UserGroups will only include the USERGROUP entities, and not any navigation property content
      
      
                  url: "/api/UserGroups",
                  data: {
                      $expand: "USERS"
                  },
                  dataType: "json"                                // the default result type is JSONP, but WebAPI does not support JSONP
              },
      

      【讨论】:

      • 对于任何想知道如何扩展多个字段的人,只需使用带有逗号分隔值的单个字符串。 $expand: ' Users, OtherProperty'
      【解决方案3】:
      read: {
          url: "http://localhost:1839/OData.svc/Claim",
          dataType: "json",
          data: {
              $expand: "Patient"
          }
      }
      

      数据只读选项。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-04-08
        • 1970-01-01
        • 1970-01-01
        • 2015-02-15
        • 2016-06-18
        • 1970-01-01
        • 1970-01-01
        • 2014-06-06
        相关资源
        最近更新 更多