Javascript 使用 removeEvents 方法删除特定事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14842629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Removing specific events with removeEvents method
提问by wowzuzz
I've just started out using this plugin and I am having some trouble removing events that I have just created. I can delete all the events when using eventClick, but not particular ones on eventClick.
我刚刚开始使用这个插件,但在删除我刚刚创建的事件时遇到了一些问题。我可以在使用 eventClick 时删除所有事件,但不能删除 eventClick 上的特定事件。
Any help would be appreciated. Here is my code.
任何帮助,将不胜感激。这是我的代码。
<script type='text/javascript'>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Trade Show Name:');
if (title) {
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay,
id: 12
},
true // make the event "stick"
);
$('input[name="startDate"]').val(start);
}
calendar.fullCalendar('unselect');
},
eventClick: function(calEvent, jsEvent, view) {
$('#calendar').fullCalendar('removeEvents', function (calEvent) {
return true;
});,
editable: true
});
});
回答by ganeshk
You can do this in 2 ways:
您可以通过两种方式执行此操作:
1) Set a unique ID to each of your events and pass those IDs to the removeEventscall.
1) 为您的每个事件设置一个唯一 ID,并将这些 ID 传递给removeEvents呼叫。
eventClick: function (calEvent, jsEvent, view) {
$('#calendar').fullCalendar('removeEvents', calEvent._id);
}
Here _idis the unique ID fullCalendar generates.
这_id是 fullCalendar 生成的唯一 ID。
2) Pass a filter function to delete the event you want.
2)通过过滤功能删除你想要的事件。
Considering that you are trying to do this in eventClick, I would suggest you use the 2nd. An example to your case is as follows:
考虑到您正在尝试在 中执行此操作eventClick,我建议您使用 2nd。您的情况的示例如下:
eventClick: function (calEvent, jsEvent, view) {
$('#calendar').fullCalendar('removeEvents', function (calEvent) {
return true;
});
}
Here the filter function passed to removeEventsaccepts the event you want to delete and returns true. Since you are doing this in eventClick, all you have to do is pass calEvent.
这里传递给的过滤器函数removeEvents接受您要删除的事件并返回 true。既然你是这样做的eventClick,你所要做的就是通过calEvent。
Hope this helps!
希望这可以帮助!

