在剑道日历中突出显示的日期仅在警报状态下工作
本文关键字:状态 工作 日期 显示 日历 | 更新日期: 2023-09-27 17:54:20
我看到过很多关于"JavaScript只在alert状态下工作"的问题,但是答案都是针对这些问题的。我正在使用剑道日历,并希望从数据库中的值突出显示特定日期。下面的代码只有在编写警报时才能正常工作。请帮忙:
var duedates = [];
function GetDueDates() {
$.ajax({
type: "POST",
url: "ChartBinder.asmx/GetDueDates",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
duedates = $.parseJSON(msg.d);
},
error: function (msg) {
alert("error");
}
});
}
$(document).ready(function () {
GetDueDates();
//当alert在这里插入时,功能工作。
var today = new Date();
$("#calendar").kendoCalendar({
change: onChange,
navigate: onNavigate,
value: today,
dates: duedates,
month: {
// template for dates in month view
content: '# if ($.inArray(+data.date, data.dates) != -1) { #' +
'<div class="' +
"dataexist" +
'"></div>' +
'# } #' +
'#= data.value #'
},
footer: "Today - #=kendo.toString(data, 'd') #"
});
$(document).find("#panelbar").kendoPanelBar({
expandMode: "single"
});
});
得到解决方案:更改代码如下:
var duedates = [];
function GetDueDates() {
$.ajax({
type: "POST",
url: "ChartBinder.asmx/GetDueDates",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
duedates = $.parseJSON(msg.d);
},
error: function (msg) {
alert("error");
} });
}
$(document).ready(function () {
GetDueDates();
setTimeout(function () { loadCalender(); }, 100);
$(document).find("#panelbar").kendoPanelBar({
expandMode: "single"
});
});
function loadCalender() {
var today = new Date();
$("#calendar").kendoCalendar({
change: onChange,
navigate: onNavigate,
value: today,
dates: duedates,
month: {
// template for dates in month view
content: '# if ($.inArray(+data.date, data.dates) != -1) { #' +
'<div class="' +
"dataexist" +
'"></div>' +
'# } #' +
'#= data.value #'
},
footer: "Today - #=kendo.toString(data, 'd') #"
});
}