[英]Fullcalendar v5 remove all events on button click
I want to remove all events in fullcalendar v5 upon click of a button, the code below works fine我想通过单击按钮删除 fullcalendar v5 中的所有事件,下面的代码工作正常
calendar.addEventSource([
{
title: 'Business Lunch',
start: '2020-04-03T01:00:00',
},
]);
But how can I able to remove/clear/delete all events after button click?但是单击按钮后如何删除/清除/删除所有事件? The older version of fullcalendar has this method
fullcalendar的老版本有这个方法
calendar.fullCalendar( 'removeEvents', []);
How about for v5? v5 怎么样? I tried the code below but it gives me an error
remove is not a function
.我尝试了下面的代码,但它给了我一个错误
remove is not a function
。 I even tried calendar.refetchEvents();
我什至试过
calendar.refetchEvents();
but nothing works.但没有任何效果。
$('.button').click(function(event) {
calendar.remove();
});
Fullcalendar v5 remove all events Fullcalendar v5 删除所有事件
calendar.removeAllEvents();
Must be called on an Event Source instance.必须在事件源实例上调用。 Use getEventSources.
使用 getEventSources。
removeEvents = calendar.getEventSources();
removeEvents.forEach(event => {
event.remove();
});
@tta & @Leandro Lazzaretti: @tta & @Leandro Lazzaretti:
Great answers, I was looking for this, and both works: but I found out an important diffenrence between them:很好的答案,我一直在寻找这个,并且两者都有效:但我发现它们之间有一个重要的区别:
calendar.removeAllEvents(); // This will NOT clear the events source array
and和
removeEvents = calendar.getEventSources();
removeEvents.forEach(event => {
event.remove(); // this will clear
});
You can check it out by doing:您可以通过执行以下操作来检查它:
removeEvents = calendar.getEventSources();
removeEvents.forEach(event => {
event.remove();
});
calendar.addEventSource('yourSourceHere');
var e = calendar.getEventSources();
console.log(e);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.