Problem removing event sources from FullCalendar (jQuery)

白昼怎懂夜的黑 提交于 2019-12-19 19:51:23

问题


Right then, I'm using FullCalendar to display events from multiple sources, some local JSON feeds, others from Google Calendar. I've implemented a feature whereby a single calendar can be displayed / hidden when it's checkbox is true or false respectively.

I'm using this code to achive it:

$('#calendar_list input','#sidebar').live('click', function() {
    if($(this).is(":checked")==true) {
        // display the calendar     
        var source = $.fullCalendar.gcalFeed("http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic");
        $('#calendar').fullCalendar('addEventSource', source);
    } else {
        // remove the calendar
        var source = $.fullCalendar.gcalFeed("http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic");
        $('#calendar').fullCalendar('removeEventSource', source);
    }
});

This example if just to show / hide a Google Calendar feed, the problem is it never hides the calendar again... if I click the check box 10 times, (1=off, 2=on, 3=off, 4=on etc) it displays 5 versions of the same calendar.

The documentation doesn't really seem to give many clues and it seems this problem has plauged a few on the Google Project site for the project.

How to I remove an event souce?! *cries*

Any help would be appreciated.


回答1:


Right then, I've actually found the solution to my problem, I decided to look back over the Google Project issues and noticed that someone had raised an issue for the same problem I was having, now the documentation says:

Source must be a reference to the original Array/URL/Function. Events from the source will immediately be removed from the calendar.

I thought this meant to remove a calendar I would have to use an identical source to the one I added, so if I added source /getEvents.php I would have to remove it in the same way, instead what it actually means is that I have to use the exact same source.

So I set the source as an item in an array (calendar id as the key) and then I can add / remove the calendar based on this, this has now solved the problem.




回答2:


You should rerender events after adding/removing a source, or maybe try to refetch events if that doesn't work. That might be the problem.



来源:https://stackoverflow.com/questions/3092394/problem-removing-event-sources-from-fullcalendar-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!