2011-04-23 27 views
2

假設我有一個重複每天的事件。現在用戶想要刪除星期一的活動,但剩下所有的活動。我怎樣才能做到這一點?現在,因爲它們都具有相同的重複ID,它將刪除所有事件。我只想要刪除一個事件。使用jquery fullcalendar刪除一系列事件中的一個事件1.5

Is there away to delete by something else then Id?就像我不能在活動上使用自己的屬性來刪除它?

+0

嗨,你怎麼解決這個問題?你能舉一些例子嗎? – user998405 2016-02-23 05:13:17

回答

2

是的,你可以使用自己的屬性。但是,當事件加載時,您需要在服務器端生成它們。

例如(我將陣列爲例)

{ 
events: [ 
    { 
     title: 'Event1', //required 
     start: '2011-04-04', //required 
     myUniqueID: '000001' //your UniqueID thats embedded in the event! 
     className: 'id000001' //your UniqueID that appears as a class on DOM and get directly using jquery 

    }, 
    { 
     title: 'Event2', 
     start: '2011-05-05' 
     myUniqueID: '000002' //your UniqueID thats embedded in the event! 
     myOtherUnqieID: 'allYearOnly', 
     yetAnotherUniqueID: 'userDelete:no', 
     myBooleanID: false, //not enclosed in '' !! 
     className: 'id000002' //your UniqueID that appears as a class on DOM and get directly using jquery 
    } 
    // etc... 
], 
color: 'yellow', // an option for the whole source 
textColor: 'black' // an option for the whole source 

}

http://arshaw.com/fullcalendar/docs/event_data/Event_Object/

閱讀關於非標準領域

+0

@ppumkin - 我知道非標準字段,但從我嘗試過的看來,您不能使用非標準字段從日曆中刪除事件(使用removevents)。如果你知道如何讓我知道。 – chobo2 2011-04-25 14:22:06

+0

嗯..我想我知道你的意思。您正嘗試從源中刪除該事件。使用http://arshaw.com/fullcalendar/docs/event_data/removeEvents/這個函數,而不是把ID放在你的唯一字段中。我從來沒有這樣做 - 但我認爲很快我將不得不做類似的事情。但試試這可能嗎? – ppumkin 2011-04-25 21:19:52

+0

@ppumkin - 是的,我試圖從日曆對象中刪除它。因此,當用戶點擊某個事件的視圖時,一旦點擊它就會點擊「只刪除該實例」,它應該從日曆中消失,並且永遠不會回來(它從數據庫中消失)。我嘗試將自己的唯一字段傳遞給removeEvents,但它什麼都不做。我認爲它使用ID。我迄今爲止提出的兩種解決方案是。 ID對於所有事件都是不容置疑的,絕不會重複。然後在服務器端檢查是否重複。當然,有一個價格是完整的日曆沒有知識或重複的事件。 – chobo2 2011-04-25 21:28:02

1

如果設置了id屬性的事件(不myUniqueId這是一個自定義屬性),那麼你可以通過使用這樣的ID刪除一個或多個事件:

.fullCalendar("removeEvents", "your_event_id_here") 
+0

您不必設置ID。看我的解決方案。 – elon 2013-02-15 15:56:59

0

當你有你所有的ID設置使用Izet的想法。

但是當你沒有ID在你的事件做這樣的(這工作還當你有ID的集):

eventClick: function(event){ 
    $('#myCalendar').fullCalendar('removeEvents',event._id); 
} 

我已清除了爲什麼問題occures: How do I delete this event from FullCalendar?

0

我爲這個答案創建了一個完整的特定解決方案,這個解決方案非常簡單。祕訣在於使用自定義屬性(在我的案例中爲excludedDate),其中包含要從每日併發事件中排除的日期。 然後,在到達此日期時,eventRender函數僅返回false。

eventRender: function(event, element, view) { 

    var theDate = event.start 
    var excludedDate = event.excludedDate; 
    var excludedTomorrrow = new Date(excludedDate); 
    //if the date is in between August 29th at 00:00 and August 30th at 00:00 DO NOT RENDER 
    if(theDate >= excludedDate && theDate < excludedTomorrrow.setDate(excludedTomorrrow.getDate() + 1)) { 
     return false; 
    } 
    } 

轉到working demo on jsfiddle