2016-09-26 141 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

相关问题