2014-05-24 30 views
4

我正在與Kendo UI一起使用odata網格。 問題是,ajax請求保持包含回調參數。導致此錯誤的原因:不支持回調參數。當我在沒有回調的情況下手動執行請求時,我的odata服務完美無缺。 有人想法如何解決這個問題?Kendo ui odata請求回叫不支持

$("#grid").kendoGrid({ 
     dataSource: new kendo.data.DataSource({ 
      type:"odata", 
      serverPaging: true, 
      serverFiltering: true, 
      serverSorting: true, 

      transport: { 
       contentType: "application/json; charset=utf-8", 
       type: "GET", 
       read: "/odata/FestivalSignUps?$inlinecount=allpages&$expand=PrefferedTasks/Task,AvailableDays,ApplicationUser", 
       dataType: "json", 
       parameterMap: function (options, type) { 
        var paramMap = kendo.data.transports.odata.parameterMap(options); 
        delete paramMap.$format; // <-- remove format parameter. 

        return paramMap; 
       } 
      }, 


      pageSize: 10, 
      schema: { 
       data: function (data) { 
        return data["value"]; 
       }, 
       total: function (data) { 
        return data["odata.count"]; 
       }, 

      } 
     }), 
     filterable:true, 
     sortable: true, 
     pageable: { 
      refresh: true, 
      pageSizes: true, 
      buttonCount: 5 
     }, 
     columns: [ 
      { field: "ApplicationUser.Email", width: 90, title: "Email" }, 

      { field: "ApplicationUser.FirstName", width: 90, title: "Voornaam" }, 

      { field: "ApplicationUser.LastName", width: 90, title: "Achternaam" }, 
      { field: "PrefferedTasks", width: 90, title: "Taken", 
       template: "#= formatTasks(data) #"}, 
      { field: "Beschikbaar", width: 90, title: "Taken" } 
     ] 

    }); 

更新 此代碼解決了這個問題:

$("#grid").kendoGrid({ 
     dataSource: new kendo.data.DataSource({     

      type: 'odata', 

      transport: { 
       read: { 
        url: "/odata/FestivalSignUps?$expand=PrefferedTasks/Task,AvailableDays,ApplicationUser", 
        dataType: "json" 
      }, 

      }, 



      schema: { 
       data: function (data) { 
        return data["value"]; 
       }, 
       total: function (data) { 
        return data["odata.count"]; 
       }, 

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

     filterable:true, 
     sortable: true, 
     pageable: { 
      refresh: true, 
      pageSizes: true, 
      buttonCount: 5 
     }, 
     columns: [ 
      { field: "ApplicationUser.Email", width: 90, title: "Email" }, 

      { field: "ApplicationUser.FirstName", width: 90, title: "Voornaam" }, 

      { field: "ApplicationUser.LastName", width: 90, title: "Achternaam" }, 
      { field: "PrefferedTasks", width: 90, title: "Taken", 
       template: "#= formatTasks(data) #"}, 
      { 
       field: "AvailableDays", width: 90, title: "Beschikbaar", 
       template: "#= formatDays(data) #" 
      }, 
     ] 

    }); 
+1

修復問題的改變究竟是什麼? – PhilBrown

+1

我花了一段時間才發現,dataType是讀取的成員而不是傳輸參數。 –

回答

7

我蓋這個問題和其他一些人在博客中,我寫道:Server-Side Filtering Using KendoUI With MVC4 WebAPI and OData.


如果你是查詢自己的數據,而不需要做跨域請求,我們可以不使用jsonp。爲此,我們只是告訴Kendo dataType讀取操作是「json」。

var dataSource = new kendo.data.DataSource({ 
    type: 'odata', // <-- Include OData style params on query string. 
    transport: { 
     read: { 
      url: "/api/Albums", 
      dataType: "json"; // <-- The default was "jsonp". 
     } 
    } 
});