这是我用来根据日期将远程数据绑定(bind)到ListView的方法。
function getListData(date) {
$.ajax({
type: "POST",
url: wcfurl + "getList",
data: '{"date":"' + date + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
processdata: true,
success: function (data) {
$.each(data, function (i, item1) {
listds = item1;
});
$("#listview").kendoListView({
dataSource: new kendo.data.DataSource({
data: JSON.parse(listds)
}),
template: kendo.template($("#template").html()),
altTemplate: kendo.template($("#altTemplate").html()),
selectable: true,
change: function () {
var index = this.select().index(), dataItem = this.dataSource.view()[index];
alert("id: " + dataItem.id + ", table: " + dataItem.tableno);
}
});
},
error: function (result) {
alert("error : " + result);
}
});
}
我通过以下方法将日期传递给此 [getListData(date)]
方法。
function initCalander() {
$.ajax({
success: function () {
var today = new Date(),
events = [+new Date(today.getFullYear(), today.getMonth(), 10),
+new Date(today.getFullYear(), today.getMonth(), 20)];
$(".calendar").kendoCalendar({
value: today,
dates: events,
change: function () {
var d = kendo.toString(this.value(), 'd');
getListData(d);
}
});
}
});
}
这最初工作完美,但如果我更改列表与当前数据重新绑定(bind)的日期,到现在为止,问题是,在 ListView 的 change
中,警告消息出现两次,第一次是它显示旧数据,第二次仅显示当前数据。
不知道是什么问题。任何帮助将不胜感激。
谢谢。
最佳答案
试试这个
function initCalander() {
$.ajax({
..
var d = kendo.toString(new Date(result.Value), 'd');
getListData(d);
..
});
}
关于javascript - 如何在剑道 ListView 中更改数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20657731/