1
我有這樣的場景:試圖調用refetchEvents後得到clientEvents不返回任何clientEvents
日曆最初加載和顯示一堆基於多個事件源事件。我也有一些下拉框可以讓用戶根據一些標準過濾日曆。但爲了確保我始終從事件源加載的最初事件集合開始工作,在開始過濾之前,我會調用.fullCalendar('refetchEvents')調用。我通過獲取客戶端事件(.fullCalendar('clientEvents'))來做到這一點。但是我遇到的問題是,在執行refreshEvents之後,當我得到客戶端事件時,即使我可以在該時間點看到日曆上的一堆事件,我也會得到0個客戶端事件。我錯過了什麼嗎?請指教。
代碼片段:
$('#calendar').fullCalendar('refetchEvents'); //commenting this out, gives me the clientEvents
var calEvents = $('#calendar').fullCalendar('clientEvents');
alert(calEvents.length + " and " + $.isArray(calEvents)); //get nothing here after refetchEvents
if (ui.checked) {
$.ajax({
type: "GET",
async: true,
url: "/Case/CalendarFilterCriteria",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: { filterOptions: data, caseId: cavo.currentCaseId },
success: function (response) {
//alert($.isArray(response.eventIds));
$.each(calEvents, function (index, value) {
//alert(index + " and " + value.id);
$('#calendar').fullCalendar('removeEvents', function (value) {
var found = 0;
$.each(response.eventIds, function (index, val) {
console.log("value " + value.id + " val " + val.id);
if (value.id === val.id) {
console.log("match found");
found = 1;
return false; //to break the inner .each loop
}
})
console.log("remove " + !found);
return !found; //if true, the event will be deleted from the calendar
})
});
}