2014-11-06 72 views
1

我希望能够基于添加和删除eventSources来过滤事件。我找不到一个很好的例子。添加/删除eventSources FullCalendar

.fullCalendar('addEventSource', source) 
.fullCalendar('removeEventSource', source) 

我想要复选框来切换这些功能的执行。我似乎无法得到功能虽然工作。

$("#target").click(function() { 
    $('#calendar').fullCalendar('removeEventSource', 'Event1'); 
}); 

这里是我的全码:

$('#calendar').fullCalendar({ 
     header: { 
    left: 'title', 
    center: 'prev,next', 
    right: 'month,agendaWeek,agendaDay,today' 
}, 
     eventLimit: { 
    'agenda': 4, // adjust to 6 only for agendaWeek/agendaDay 
    'default': true // give the default value to other views 
     }, 
      eventSources: [ 
      { 
       title: 'Event1', 
       url: "http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic" 
      }, 

      { 

       url: 'https://www.google.com/calendar/feeds/vineyardcincinnati.com_o6jncckm5ka55fpragnbp4mk9c%40group.calendar.google.com/public/basic' 
      }, 
     { 
     url: "https://www.google.com/calendar/feeds/ht3jlfaac5lfd6263ulfh4tql8%40group.calendar.google.com/public/basic" 
      } 
     ], 

     eventClick: function(event) { 
      // opens events in a popup window 
      window.open(event.url, 'gcalevent', 'width=700,height=600'); 
      return false; 
     }, 

     loading: function(bool) { 
      if (bool) { 
       $('#loading').show(); 
      }else{ 
       $('#loading').hide(); 
      } 
     } 

    }); 
+0

“源参数相当灵活。您可以提供一个事件源的Array/URL/Function,或者您可以指定完整的事件源对象。“标题不是其中之一 – 2014-11-06 11:00:19

+0

感谢,由于某种原因,似乎也不工作$('## ')。fullCalendar('removeEventSource',eventSources [0]); – byrdr 2014-11-06 14:24:29

+0

URL适用于我:$(“#target”).click(function(){ alert(“Handler for .click()called。”) ); $('#calendar')。fullCalendar('removeEventSource','https://www.google.com/calendar/feeds/vineyardcincinnati.com_o6jncckm5ka55fpragnbp4mk9c%40group.calendar.google.com/public/basic'); }); – byrdr 2014-11-06 14:49:41

回答

1

这里是我用来获取该功能的完整代码:

HTML:

<form id="#calendar_list"> 
<input class="checkbox" type="checkbox" checked>Event Group 1<br> 
<input class="checkbox1" type="checkbox" checked>Event Group 2<br> 
<input class="checkbox2" type="checkbox" checked>Event Group 3<br> 
</form> 

的Javascript:

$(".checkbox").change(function() { 
    if(this.checked) { 
     $('#calendar').fullCalendar('addEventSource', 'https://www.google.com/calendar/feeds/vineyardcincinnati.com_o6jncckm5ka55fpragnbp4mk9c%40group.calendar.google.com/public/basic'); 
    } 
    else{ 
    $('#calendar').fullCalendar('removeEventSource', 'https://www.google.com/calendar/feeds/vineyardcincinnati.com_o6jncckm5ka55fpragnbp4mk9c%40group.calendar.google.com/public/basic'); 
    } 
});