2017-02-10 41 views
1

大家好,我對Kendo UI Grid組件變得瘋狂了。我正在使用dataSource.transport.read在GET中加載JSON Jersey服務。該代碼是這樣的:Kendo UI數據源傳輸讀取忽略數據參數

var args = new Object(); 
    args.procomfilter = "058091_054051"; 
    args.userGrid = "false"; 
    args.take = "20"; 
    args.skip = "0"; 
    args.row = "Comuni"; 

var _dataSourceGrid = new kendo.data.DataSource({ 
     pageSize: 20, 
     serverPaging: true, 
     serverSorting: true, 
     serverFiltering: true, 
     transport: { 
      read:{ 
       type: "GET", 
       url: "services/viewData/filtracomuni" , 
       data: JSON.stringify(args), 
       cache: false } } .... 

var _grid = $(gridId).kendoGrid({ 
     dataSource: _dataSourceGrid, 
     columnMenuInit: function(e) { 
      var item = e.container.find(".k-columns-item"); 
      item.prev(".k-separator").remove(); 
      item.remove(); 
     }, 
     width: "100%", 
     height: "100%", 
     toolbar: kendo.template($(gridId+"Template").html()), 
     resizable: true, 
     //sortable: true, 
     columnMenu: !userGrid, 

...

上螢火我看到參數表是完全忽略

但如果我直接撥打電話:

$(_gridId).kendoGrid({ 
    dataSource: { 
     transport: { 
      read: { 
         type: "POST", 
         url: "services/viewData/filtracomuni", 
          data: JSON.stringify(args) 
        } 

     } 
    } 
}); 

它的工作原理,爲什麼? 非常感謝

回答

0

當您實例化數據源時,您的JSON.stringify(data)會立即執行,並且此時您的數據尚未準備好。爲了解決這個問題,要包裝你的字符串化的功能:

var _dataSourceGrid = new kendo.data.DataSource({ 
     transport: { 
      read:{ 
       type: "GET", 
       url: "services/viewData/filtracomuni" , 
       data: function() { return JSON.stringify(args); }, 
       dataType : "json", 
       cache: false 
      } } 

....

+0

thak你了 – djonthenet