2016-10-19 242 views
2

打破了我的頭,我需要一點幫助。FullCalendar通過event.id或event.source刪除所有eventSources或事件

故事背景

我創建一個日曆選擇工具來凸顯無天與fullCalendar背景事件。用戶界面允許拖動選擇日期或突出顯示一天。當用戶再次選擇突出顯示時,應該將其刪除。使用AJAX,我可以添加或刪除選擇內容,並且在刷新頁面時,以前的事件將從容器上的data-events加載。

<div class="container" data-class="calendar" data-events='<?=$jsoncalendarinfo?>' data-user-id="<?php echo $id; ?>"> 
    <div class="row"> 
     <div class="col-lg-3 feedback p-y-2"> 
     <?php 
      foreach ($calendarinfo as $item) { 
     ?> 
      <ul data-start="<?=strtotime($item->date_from)?>"> 
       <li>Vrij</li> 
       <li><?=date('d/m/Y',strtotime($item->date_from))?> - <?=date('d/m/Y',strtotime($item->date_to))?></li> 
      </ul> 
     <?php 
      } 
     ?> 
     </div> 
     <div class="col-lg-9 calendar p-y-2"><!-- fullcalendar.js rendering --></div> 
    </div> 
</div> 

問題

當我刷新頁面,我點擊一個亮點(一天或範圍),所有的亮點都被刪除。現在我必須補充我可能會在events,eventSourceeventSources之間感到困惑。這個文檔對它背後的想法並不是非常明確,所以它更像是一個對我而言的嘗試和錯誤。

我的代碼

eventSources: [this.formatEvents(this.events)], 
selectOverlap: function (event) { 
    self.calendar.fullCalendar(events.removeEventSource, event.source); 
    self.removeFeedback(event); 
    return !event.block; 
}, 

我可能已經被劫持的這個功能得到我想要的東西,但同樣,我似乎無法找到要取消選擇高亮顯示的日期或範圍的恰當方法。這不是unselect方法。

他們的代碼

沒有在selectOverlap =>self.calendar.fullCalendar 可用實例的文檔指出您可以刪除eventSources但不events ??? 我試圖在eventseventSources =>中添加我的jsondata => f ***的區別是什麼? 我試圖刪除event.idevent.source =>他們都清除!?! 我試圖清理event對象,但是在event.sources.events中,所有事件都是通用嵌套的。 我進入圖書館看看發生了什麼=> ln。 11161

function removeEventSource(matchInput) { 
    removeSpecificEventSources(
     getEventSourcesByMatch(matchInput) 
    ); 
} 


// if called with no arguments, removes all. 
function removeEventSources(matchInputs) { 
    if (matchInputs == null) { 
     removeSpecificEventSources(sources, true); // isAll=true 
    } 
    else { 
     removeSpecificEventSources(
      getEventSourcesByMatchArray(matchInputs) 
     ); 
    } 
} 

它基本上從不比較,因爲對象太不同了。如果我使用我的event.id,它會嘗試與事件對象進行比較。當我使用event.source它發現在同一來源和BAM下的所有事件,全部消失:s

任何人在這裏爲我歡呼?

DEMO

https://jsfiddle.net/tive/vxrkmmn3/

只需點擊高亮顯示的日期。這些是2個範圍,應該只刪除一個範圍。不幸的是它刪除了所有 如果您突出顯示其他日期或範圍,則可以將其刪除而不會出現問題。一旦頁面刷新,它不再工作。

+2

事件源全部文檔只是分組事件的方式,如果有用的話您的活動來自不同的來源(後端)。如果您沒有多個後端或其他邏輯分組事件,則可能不需要它們。所以如果你刪除一個事件源,你將刪除所有來自該源的事件。您是否在嘗試刪除單個事件時選擇它?也許https://fullcalendar.io/docs/event_data/removeEvents/是你需要的方法 – ADyson

+0

聽起來你是對的!不能相信我錯過了,因爲我確信我已經在尋找這個功能。要儘快嘗試。 –

+1

對!很愚蠢......'self.calendar.fullCalendar(events.removeEvents,event.id);'就像一個魅力。隨意添加這個答案。 –

回答

1

事件來源只是分組事件的方式,如果您的事件來自不同的來源(後端),則很有用。如果您沒有多個後端或其他邏輯分組事件,則可能不需要它們。

因此,如果您刪除事件源,您將刪除所有來自該源的事件。

如果您嘗試在選擇它時刪除單個事件,那麼RemoveEvents方法就是您需要的方法。

的簽名是:

.fullCalendar('removeEvents' [, idOrFilter ]) 

其中idOrFilter或者是一個事件ID(你可以從由selectOverlap方法提供的事件對象來獲取),或着眼於一個事件,如果它應該決定一個功能被刪除或沒有。

https://fullcalendar.io/docs/event_data/removeEvents