【发布时间】:2015-05-01 12:58:47
【问题描述】:
我正在使用fullcalendar.io
我通过 evenSources 添加事件来动态填充我的日历。如:
$('.add-more-events').on('click', function(){
var myEventSourceUrl = // ... get the event source url somehow
var eventSourceColor = // ... get the color for this source
var eventSource = {
type: 'GET',
url: myEventSourceUrl,
color: eventSourceColor
};
$('.my-calendar').fullCalendar('addEventSource', eventSource);
}
同样,我通过 eventSource 删除事件来动态取消填充我的日历。如:
$('.remove-some-events').on('click', function(){
var myEventSourceUrl = // ... get the event source url somehow
var eventSourceColor = // ... get the color for this source
var eventSource = {
type: 'GET',
url: myEventSourceUrl,
color: eventSourceColor
};
$('.my-calendar').fullCalendar('removeEventSource', eventSource);
}
到目前为止,一切都很好:从视觉上看,事件在日历中出现(已填充),而在日历中消失(未填充),正如预期的那样。也就是说,每当我点击相关按钮时。
在某些时候,我想重新初始化我的日历并重新显示我日历中最后出现的事件(保留我想的最后一个 eventSources)。
伪代码如下所示:
1. Back up my events
2. Destroy my calendar
3. Create & initialize new calendar
4. Add the backed up events (see step 1) to the new calendar
所以我实现了上述如:
var clientEvents = $('.my-calendar').fullCalendar('clientEvents'); /* [1] */
$('.my-calendar').fullCalendar('destroy'); /* [2] */
$('.my-calendar').fullCalendar(calendarOptions); /* [3] */
var arrayLengthClientEvents = clientEvents.length;
for (var i = 0; i < arrayLengthClientEvents; i++) {
$('.my-calendar').fullCalendar( 'addEventSource', clientEvents[i].source); /* [4] */
}
但由于某种原因,我在调用 $('.my-calendar').fullCalendar('clientEvents') 时收到重复事件。
注意:切换周时似乎会发生这种情况,但不确定,可能无关。
资源:
- When using jquery fullCalendar, Why am i seeing duplicate events after switching months?
- http://fullcalendar.io/docs/event_data/Event_Source_Object/
- http://fullcalendar.io/docs/event_data/removeEventSource/
- http://fullcalendar.io/docs/event_data/clientEvents/
- filtering events with clientEvents method on fullCalendar
- JQuery Full Calendar - edit calendar view after initialization
【问题讨论】:
标签: javascript jquery calendar fullcalendar