从FullCalendar (jQuery)删除事件源出现问题

时间:2022-12-04 23:20:41

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.

此时,我正在使用FullCalendar显示来自多个源的事件,一些本地JSON提要,另一些来自谷歌Calendar。我实现了一个特性,当一个日历的复选框分别为真或假时,可以显示/隐藏它。

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.

这个例子如果只是显示/隐藏一个谷歌日历提要,问题是它不会再次隐藏日历……如果我点击10次复选框,(1=off, 2=on, 3=off, 4=on等等)它会显示相同日历的5个版本。

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.

如有任何帮助,我们将不胜感激。

2 个解决方案

#1


8  

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.

源必须是对原始数组/URL/函数的引用。来自源的事件将立即从日历中删除。

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.

我认为这意味着要删除一个日历,我将不得不使用一个相同的源到我添加的那个,所以如果我添加了源/getEvents。我必须以同样的方式删除它,实际上它的意思是我必须使用相同的源。

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.

因此,我将源设置为数组中的一个项(日历id作为键),然后基于此添加/删除日历,这就解决了问题。

#2


1  

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.

您应该在添加/删除一个源之后重新运行事件,或者如果无法工作,则尝试重新获取事件。这可能就是问题所在。

#1


8  

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.

源必须是对原始数组/URL/函数的引用。来自源的事件将立即从日历中删除。

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.

我认为这意味着要删除一个日历,我将不得不使用一个相同的源到我添加的那个,所以如果我添加了源/getEvents。我必须以同样的方式删除它,实际上它的意思是我必须使用相同的源。

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.

因此,我将源设置为数组中的一个项(日历id作为键),然后基于此添加/删除日历,这就解决了问题。

#2


1  

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.

您应该在添加/删除一个源之后重新运行事件,或者如果无法工作,则尝试重新获取事件。这可能就是问题所在。