我正在使用full calendar plugin v3。当我指定参数时,问题是removeEventSource函数不起作用。我试图将Id,URL作为参数,并使用refetchEvents但没有运气。
$('#calendar').fullCalendar( 'removeEventSource'); //working without parameters
$('#calendar').fullCalendar( 'removeEventSource', 1); //does not work
数组:
var events = [
{ id: 1,
title: 'dinner',
start: '2016-09-14',
end: '2016-09-14'
},
{ id: 2,
title: 'All Day Event',
start: '2016-09-10',
end: '2016-09-10'
},
{ id: 3,
title: 'Long Event',
start: '2016-09-10',
end: '2016-09-10'
},
{ id: 4,
title: 'Repeating Event',
start: '2016-09-09T16:00:00',
end: '2016-09-09'
}
]
使用日历
var calender = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: '2016-09-12',
navLinks: true,
selectable: true,
droppable: true,
selectHelper: true,
select: function(start, end) {
var title = prompt('Event Title:');
var eventData;
if (title) {
eventData = {
title: title,
start: start,
end: end
};
$('#calendar').fullCalendar('renderEvent', eventData, true);
}
$('#calendar').fullCalendar('unselect');
},
drop: function() {
if ($('#drop-remove').is(':checked')) {
$(this).remove();
}
}
,
editable: true,
eventLimit: true,
events : events
});
点击活动
$('body').on('click','.fc-close',function(e){
//alert('remove event');
$('#calendar').fullCalendar( 'removeEventSource', 1);
$('#calendar').fullCalendar( 'refetchEvents' );
});
答案 0 :(得分:1)
您对eventSources
和events
感到有点困惑,evenSource是事件的集合,因此当您在初始化中传递events
默认eventSource 初始化时没有id
,这就是为什么它只在你没有传递任何id时工作。传递eventSource的正确方法是将事件嵌入其中并给出一个id每个eventSource项目如下
var eventSrc = [
{
id:1,
events : [{
id: 1,
title: 'dinner',
start: '2016-09-14',
end: '2016-09-14'
},
{
id: 2,
title: 'All Day Event',
start: '2016-09-10',
end: '2016-09-10'
}]
},
{
id:2,
events : [{
id: 1,
title: 'camping',
start: '2016-08-14',
end: '2016-08-14'
},
{
id: 2,
title: 'sports day',
start: '2016-08-10',
end: '2016-08-10'
}]
}
]
初始化
var calender = $('#calendar').fullCalendar({
//other stuff
eventSources : eventSrc
});
现在只需传递eventSource的id即可将其删除
$('#calendar').fullCalendar( 'removeEventSource', 1);