大家好,我对Kendo UI Grid组件感到疯狂。我使用dataSource.transport.read在GET中加载JSON Jersey服务。代码是这样的:
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,
...
在firebug上我发现args完全被忽略了但如果我直接打电话:
$(_gridId).kendoGrid({
dataSource: {
transport: {
read: {
type: "POST",
url: "services/viewData/filtracomuni",
data: JSON.stringify(args)
}
}
}
});
它有效,为什么? 非常感谢
答案 0 :(得分:0)
当您实例化数据源时,您的JSON.stringify(data)
会立即执行,此时您的数据尚未就绪。要解决此问题,您需要将stringify包装在函数中:
var _dataSourceGrid = new kendo.data.DataSource({
transport: {
read:{
type: "GET",
url: "services/viewData/filtracomuni" ,
data: function() { return JSON.stringify(args); },
dataType : "json",
cache: false
} }
...