首页 文章

有没有办法取消选择所有取消选择使用selectc回调使用'renderEvent'功能在fullcalendar中呈现的所有事件

提问于
浏览
0

我使用select回调来渲染事件 . 有没有办法取消选择使用fullcalendar中带有'renderEvent'功能的select回调渲染的所有事件?

select: function(start, end) {
  var eventData = {
    id: 1,
    title: 'schedule',
    start: start,
    end: end,
  };
  $('#calendar').fullCalendar('renderEvent', eventData, true);
}

对于所有选择操作,我将新事件呈现为完整日历 . 那么有没有办法清除通过select回调添加的所有渲染事件 .

1 回答

  • 0

    removeEvents函数(https://fullcalendar.io/docs/event_data/removeEvents/)删除事件 .

    您需要指定要删除的ID,或创建一个决定要删除哪些事件的回调 . 由于您首先创建了事件,因此您应该知道它们的ID才能执行此操作 .

    //to delete a single known ID
    $('#calendar').fullCalendar('removeEvents', 123456);
    

    或者,使用您持有的ID列表更复杂(例如,您之前使用“select”回调创建的事件的ID):

    $('#calendar').fullCalendar('removeEvents', function(evt) {
      var del = false;
      $.each(yourIDArray, function(index, value)
      {
        //if the ID matches one in the array, it should be deleted, so set the return value to true as per the docs
        if (evt.id == value) del = true;
        return false; //used to break out from the .each loop, no point continuing once we found it
      });
      return del;
    });
    

    此功能可用于日历上的任何事件,而不仅仅是通过用户选择创建的事件 .

相关问题