调用 refetchEvents 后尝试获取 clientEvents 不会返回任何 clientEvents
我有这样的场景:
日历最初加载并显示一堆基于多个事件源的事件。我还有一些下拉框,可以让用户根据某些条件过滤日历。但为了确保我始终处理从事件源加载的初始事件集,我在开始过滤之前调用 .fullCalendar('refetchEvents') 调用。我通过获取客户端事件 (.fullCalendar('clientEvents')) 来做到这一点。但我遇到的问题是,当我执行刷新事件后获取客户端事件时,我得到 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
})
});
}
I've this scenario:
The calendar loads initially and shows a bunch of events based on multiple event sources. I also have some dropdown boxes that lets the user filter the calendar based on some criteria. But to make sure that I always work off of the initial set of events that were loaded from the event sources, I call the .fullCalendar('refetchEvents') call before I start filtering. I do this by getting the client events (.fullCalendar('clientEvents')). But the problem I have is that when I get the client events after I do a refreshEvents, I get 0 client events, even though I can see a bunch of events on the calendar at that point of time. Am I missing something? Please advise.
Code snippet:
$('#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
})
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题是
refetchEvents
正在异步进行 ajax 调用。这意味着当您调用$('#calendar').fullCalendar('clientEvents')
时,不一定会检索到数据。Your problem is that
refetchEvents
is making an ajax call asynchronously. Which means that data hasn't necessarily been retrieved when you call$('#calendar').fullCalendar('clientEvents')
.