调用 refetchEvents 后尝试获取 clientEvents 不会返回任何 clientEvents

发布于 2024-12-22 01:43:06 字数 1637 浏览 0 评论 0原文

我有这样的场景:

日历最初加载并显示一堆基于多个事件源的事件。我还有一些下拉框,可以让用户根据某些条件过滤日历。但为了确保我始终处理从事件源加载的初始事件集,我在开始过滤之前调用 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩人痒 2024-12-29 01:43:06

您的问题是 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').

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文