2011-12-17 62 views
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 
     }) 
    }); 
}       

回答

0

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