2013-07-21 37 views
0

我有一個綁定到kendoui數據源的移動listview指向一個odata服務。我在數據源配置中有一個$ 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> 

回答

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 
      }, 
. 
. 
. 
3

的數據和$拓展屬於讀取對象內。你的答案越來越近了。

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 
     }, 
+0

對於任何人想知道如何擴展多個字段,只需使用逗號分隔值的單個字符串。 '$ expand:'Users,OtherProperty'' –