FullCalendar按ID删除外部事件

我正在使用FullCalendar和jQuery UI将“Days Off”拖动到我的日历上作为背景事件。

由于您无法在FullCalendar中单击后台事件,因此我创建了一个列表,其中包含我的rest日以及旁边的“删除”按钮,其中事件ID为数据属性。

但是,当我单击“删除”按钮时,即使它具有正确的ID,也不会删除该事件。

请看看这个jsFiddle: https ://jsfiddle.net/aaroncadrian/odhL964L/

为了向您显示事件ID已正确更新,我删除了事件的背景渲染,以便您可以单击该事件以显示其ID。 您还可以在按钮及其data-id属性中查看事件ID。 以下是删除事件的代码,但不起作用。

$('.remove').click(function(){ // Get the ID for the event from the button var id = $(this).data('id'); // Remove the event. **DOES NOT WORK** $('#calendar').fullCalendar('removeEvents', id); }); 

你能告诉我如何通过点击相应的按钮删除活动吗? 同样,理想情况下,我希望将这些被拖动的事件渲染为背景事件。

UPDATE

我在加载时向页面添加了一个事件及其相应的按钮,并且在页面加载时呈现事件后,删除事件的function起作用。 那么我需要采取哪些不同的做法,以便删除到日历上的外部事件可以以相同的方式删除?

https://jsfiddle.net/oLe2Lgxs/

改变你的

 var button = ''; // Create remove button with data-id attribute with event ID 

 var button = ''; // Create remove button with data-id attribute with event ID 

 $('.remove').click(function(){ 

 $('#daysOff').on('click', 'button.remove', function(){ 

从日历中删除项目。

不确定为什么使用内部事件_id适用于您指定的ID不起作用的地方。

您还可以使用$(this).parent()删除 li日期/按钮条目.remove(); 在点击处理程序内。