我使用此日历http://w3widgets.com/responsive-calendar/
我需要在页面加载后显示一些事件,所以我添加了ajax和'edit'函数。
加载函数如下所示:
function loadcalendar(){
$('#calendar').responsiveCalendar('clearAll');
$.ajax({
type:'POST',
url:'getcalendar.php',
data: {},
success: function (response)
{
$('#calendar').responsiveCalendar('edit', response);
}
});
php文件返回类似:
{\"2014-04-30\": {\"number\": 1, \"badgeClass\": \"badge-warning\"}}
问题是,它正确地清除所有事件,因此id应该是正确的 'edit'函数似乎也正常工作,因为当我直接输入事件(而不是变量)时它正确显示
答案 0 :(得分:0)
$ parseJSON(响应);
为我工作。
答案 1 :(得分:0)
这里是一个完整的示例,用于从ajax获取每个月的叶子。必须有一个更好的方法来做到这一点,但这解决了我的问题。
$('.panel-heading').on('click',
function(firstDay,lastDay) {
$.ajax({
type: 'GET',
url: "ViewPlannedLeaveJson",
data: { dateFrom: formatDate(firstDay), dateTo: formatDate(lastDay) },
dataType: "json",
success: function(result) {
$($(currentTag).next('.panel-body').children('.responsive-calendar')[0])
.responsiveCalendar({
onDayClick: function(events) { console.log('Click is Disabled') },
onMonthChange: function () {
GetLeaves(this);
},
events:
JSON.parse(result)
});
},
error: function(response) {
alert("error has occured while retreiving leaves for this user");
}
});
}
});
function GetLeaves(currentCalender) {
var year = currentCalender.currentYear;
var month = currentCalender.currentMonth ;
var firstDay = new Date(year, month, 1);
var lastDay = new Date(year, month + 1, 0);
$.ajax({
type: 'GET',
url: "ViewPlannedLeaveJson",
data: {dateFrom: formatDate(firstDay), dateTo: formatDate(lastDay) },
dataType: "json",
success: function(result) {
//Edit Code
$($(currentCalender)[0].$element).responsiveCalendar('edit', JSON.parse(result)
);
},
error: function(response) {
alert("error has occured while retreiving leaves for this month");
}
});
}