使用removeEvents方法删除特定事件 [英] Removing specific events with removeEvents method
问题描述
我刚开始使用这个插件,并且在删除刚刚创建的事件时遇到了一些麻烦。我可以在使用eventClick时删除所有事件,但不能在eventClick上删除所有事件。
任何帮助将不胜感激。这是我的代码。
< 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({
标题:{
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 //创建事件棒
);
$('input [name =startDate]')。val(start);
}
calendar.fullCalendar('unselect');
},
eventClick:function(calEvent,jsEvent,view){
$('#calendar')。fullCalendar('removeEvents',function(calEvent){
return true ;
});,
editable:true
});
});
您可以通过两种方式完成此操作:
1)为每个事件设置一个唯一的ID并将这些ID传递给 removeEvents
调用。
eventClick:function(calEvent,jsEvent,view){
$('#calendar')。fullCalendar('removeEvents',calEvent。 _ID);
这里 _id
是
2)传递过滤器函数以删除所需的事件。
考虑到你试图在 eventClick
中做到这一点,我建议你使用2nd。以下是一个例子:
eventClick:function(calEvent,jsEvent,view){
$( '#calendar')。fullCalendar('removeEvents',function(calEvent){
return true;
});
}
传递给 removeEvents
接受你想要删除的事件,返回true 。既然你在 eventClick
中这样做,你所要做的就是传递 calEvent
。
希望这有助于!
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.
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
});
});
You can do this in 2 ways:
1) Set a unique ID to each of your events and pass those IDs to the removeEvents
call.
eventClick: function (calEvent, jsEvent, view) {
$('#calendar').fullCalendar('removeEvents', calEvent._id);
}
Here _id
is the unique ID fullCalendar generates.
2) Pass a filter function to delete the event you want.
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: function (calEvent, jsEvent, view) {
$('#calendar').fullCalendar('removeEvents', function (calEvent) {
return true;
});
}
Here the filter function passed to removeEvents
accepts the event you want to delete and returns true. Since you are doing this in eventClick
, all you have to do is pass calEvent
.
Hope this helps!
这篇关于使用removeEvents方法删除特定事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!