1
我正在使用jquery和fullcalendar来安排活动。当用户选择一个时间段时,日历右侧会显示一个表单,他们可以在其中输入更多详细信息。如何删除未保存的事件?
通过'选择'回调,我在日历上呈现一个临时事件,这样我的用户在填写表单时就会有视觉反馈。
但是,当他们错误地选择一个时隙时,他们能够选择一个新的时隙。然而,这会在日历上呈现第二个(也可能是第三个,第四个......)事件。我想我可以使用'eventAfterRender(event,element)'回调函数element.siblings()。remove(),但是这个失败,因为每个事件的每个事件都使用每个renderEvent调用eventAfterRender。
也许有一个回调或方法,我失踪,但正如我所看到的,没有简单的方法来删除“未保存”的事件。
下面是一些示例代码。
var fullCal = ''; $(function() { fullCal = $('#fullcalendar').fullCalendar({ // options select: SelectDate, eventAfterRender: function(event, element) { // this does not work as it simply just keeps the last event in the DOM. element.siblings().remove() }, viewDisplay: UnselectDate // hides and clears the form, intended behavior }); }); function SelectDate(startDate, endDate, allDay, jsEvent, view) { $('#BijlesForm').show(); var BijlesEvent = {start: startDate, end: endDate, title: 'Bijles', allDay: false}; fullCal.fullCalendar('renderEvent', BijlesEvent); //fill the form }