我有一个Kendo Grid,我想根据标志值切换DataSource。我为此创建了两个DataSource变量,并根据标志值将它们传递给Kendo Grid DataSource属性。像这样dataSource: flag == 1 ? originalDataSource : backupDataSource
var flag = 1;
//DataSource 1
var backupDataSource = new kendo.data.DataSource({
transport: {
read: {
url: "/MyController/MyAction1",
dataType: "json",
data: {
ID : "1"
},
}
},
change: function (e) {},
error: function () {},
pageSize: 10,
schema: {
model: {
fields: {
Id: { type: "number" },
Date: { type: "date" },
Name: { type: "string" }
},
},
}
});
// DataSource 2
var originalDataSource = new kendo.data.DataSource({
transport: {
read: {
url: "/MyController/MyAction2",
dataType: "json",
data: {
ID : "1"
},
}
},
change: function (e) {},
error: function () {},
pageSize: 10,
schema: {
model: {
fields: {
Id: { type: "number" },
Date: { type: "date" },
Name: { type: "string" }
},
},
}
});
//Calling Kendo Grid
$("#campaign-queue").kendoGrid({
dataSource: flag == 1 ? originalDataSource : backupDataSource,
filterable: true,
sortable: true,
columns: [
{
field: "Id",
width: 55,
filterable: {
search: true,
extra: false
}
},
{
field: "Name",
width: 143,
filterable: {
extra: false
}
}
],
pageable: {
previousNext: true,
pageSize: 10
}
});
但这并不像我期待的那样有效。仅创建了originalDataSource
,但backupDataSource
始终为空。我究竟做错了什么?任何帮助将不胜感激。感谢。