Fullcalendar V4 - clear all events

前端 未结 4 1303
清歌不尽
清歌不尽 2020-12-21 20:55

I\'m loading dynamic events from a JSON source, but each time I click a different room, I want to clear all the events prior to fetching the new ones

I have attempte

相关标签:
4条回答
  • 2020-12-21 21:03

    version 5.4.0

    https://fullcalendar.io/docs/Event-remove

    $('#calendar').fullCalendar('removeEvents');

    0 讨论(0)
  • 2020-12-21 21:15

    You can call removeAllEvents function to delete all event without refreshing the whole page :

    document.addEventListener('DOMContentLoaded', function () {
         var calendarEl = document.getElementById('calendar');
    
         var calendar = new FullCalendar.Calendar(calendarEl, {/*OPTIONS*/});
    
         $('#button').on('click', function () {
              calendar.removeAllEvents();
         });
    });
    
    0 讨论(0)
  • 2020-12-21 21:15

    version 5 does not support the "removeEvents" function. you can loop through the list of events and delete them one by onevar listeEvent = calendar.getEvents();listeEvent.forEach(event => { event.remove()});

    0 讨论(0)
  • 2020-12-21 21:23

    You are absolutely spot on, I'm having a particularly slow day on picking things up!

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

    Was the solution, as you suggested @ADyson

    0 讨论(0)
提交回复
热议问题