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 }