Fullcalendar V4 - 清除所有事件

Jas*_*ams 3 jquery fullcalendar fullcalendar-4

我正在从 JSON 源加载动态事件,但是每次单击不同的房间时,我都想在获取新事件之前清除所有事件

我试图清除 eventSource 但无济于事

var eventSource = calendar.getEventSources()
eventSource.remove();
Run Code Online (Sandbox Code Playgroud)

这导致错误:

Uncaught TypeError: eventSource.remove is not a function
Run Code Online (Sandbox Code Playgroud)

我以前一直在使用 V3,但升级到 V4 并且文档有点难以理解如何清除事件。

Jas*_*ams 8

你绝对是对的,我今天收拾东西特别慢!

var eventSources = calendar.getEventSources(); 
var len = eventSources.length;
for (var i = 0; i < len; i++) { 
    eventSources[i].remove(); 
} 
Run Code Online (Sandbox Code Playgroud)

是解决方案,正如ADyson所建议的那样


ami*_*ine 5

您可以调用removeAllEvents函数删除所有事件而无需刷新整个页面:

document.addEventListener('DOMContentLoaded', function () {
     var calendarEl = document.getElementById('calendar');

     var calendar = new FullCalendar.Calendar(calendarEl, {/*OPTIONS*/});

     $('#button').on('click', function () {
          calendar.removeAllEvents();
     });
});
Run Code Online (Sandbox Code Playgroud)


Ash*_*mar 5

版本5.4.0

事件删除

$('#calendar').fullCalendar('removeEvents');
Run Code Online (Sandbox Code Playgroud)