【问题标题】:Trying to get clientEvents after calling refetchEvents does not return any clientEvents调用 refetchEvents 后尝试获取 clientEvents 不会返回任何 clientEvents
【发布时间】:2011-12-17 17:03:05
【问题描述】:

我有这种情况:

日历最初加载并显示基于多个事件源的一系列事件。我还有一些下拉框,可让用户根据某些条件过滤日历。但是为了确保我始终处理从事件源加载的初始事件集,我在开始过滤之前调用了 .fullCalendar('refetchEvents') 调用。我通过获取客户端事件 (.fullCalendar('clientEvents')) 来做到这一点。但我遇到的问题是,当我在执行 refreshEvents 后获得客户端事件时,我得到 0 个客户端事件,即使当时我可以在日历上看到一堆事件。我错过了什么吗?请指教。

代码sn-p:

$('#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
        })
    });
}                        

【问题讨论】:

    标签: jquery-plugins fullcalendar


    【解决方案1】:

    您的问题是 refetchEvents 正在异步进行 ajax 调用。这意味着当您调用$('#calendar').fullCalendar('clientEvents') 时,数据不一定被检索到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-21
      • 1970-01-01
      • 2021-08-28
      相关资源
      最近更新 更多