2016-09-26 64 views
0

我使用full calendar plugin V3。問題是,當我指定參數時,removeEventSource函數不起作用。我試圖把標識,URL作爲參數應用,並使用refetchEvents但沒有運氣。完整的日曆插件不刪除事件

$('#calendar').fullCalendar('removeEventSource'); //working without parameters 

$('#calendar').fullCalendar('removeEventSource', 1); //does not work 

陣列:

var events = [ 
      { id: 1, 

       title: 'dinner', 
       start: '2016-09-14', 
       end: '2016-09-14' 
      }, 
      { id: 2, 
       title: 'All Day Event', 
       start: '2016-09-10', 
       end: '2016-09-10' 
      }, 
      { id: 3, 
       title: 'Long Event', 
       start: '2016-09-10', 
       end: '2016-09-10' 
      }, 
      { id: 4, 
       title: 'Repeating Event', 
       start: '2016-09-09T16:00:00', 
       end: '2016-09-09' 
      } 
     ] 

intilize日曆

var calender = $('#calendar').fullCalendar({ 
    header: { 
    left: 'prev,next today', 
      center: 'title', 
      right: 'month,agendaWeek,agendaDay' 
     }, 
     defaultDate: '2016-09-12', 
     navLinks: true, 
     selectable: true, 
     droppable: true, 
     selectHelper: true, 
     select: function(start, end) { 
      var title = prompt('Event Title:'); 
      var eventData; 
      if (title) { 
       eventData = { 
        title: title, 
        start: start, 
        end: end 
       }; 
       $('#calendar').fullCalendar('renderEvent', eventData, true); 
      } 
      $('#calendar').fullCalendar('unselect'); 
     }, 
     drop: function() { 
      if ($('#drop-remove').is(':checked')) { 
       $(this).remove(); 
      } 
     } 
     , 
     editable: true, 
     eventLimit: true, 
     events : events 
    }); 

點擊事件

$('body').on('click','.fc-close',function(e){ 
    //alert('remove event'); 
    $('#calendar').fullCalendar('removeEventSource', 1); 
    $('#calendar').fullCalendar('refetchEvents'); 



    }); 

回答

1

你是一個有點糊塗了eventSourcesevents,一個evenSource是事件的集合,所以當你傳遞events在初始化一個默認的EventSource與沒有id這就是爲什麼當你不傳遞任何id.Correct的方式來傳遞的EventSource唯一的初始化工作是嵌入你裏面的事件,給一個ID給每個EventSource的項目像下面

var eventSrc = [ 
       { 
        id:1, 
        events : [{        
           id: 1, 
           title: 'dinner', 
           start: '2016-09-14', 
           end: '2016-09-14' 
           }, 
           {  
           id: 2, 
           title: 'All Day Event', 
           start: '2016-09-10', 
           end: '2016-09-10' 
          }] 
       }, 
       { 
        id:2, 
        events : [{         
           id: 1, 
           title: 'camping', 
           start: '2016-08-14', 
           end: '2016-08-14' 
           }, 
           {  
           id: 2, 
           title: 'sports day', 
           start: '2016-08-10', 
           end: '2016-08-10' 
          }] 
       } 
       ] 

在初始化

var calender = $('#calendar').fullCalendar({ 
              //other stuff 
              eventSources : eventSrc 
              }); 

的EventSource的現在只是通過ID刪除它

$('#calendar').fullCalendar('removeEventSource', 1); 
+0

感謝,它的工作。 – nemrrached