2017-02-10 39 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