Jquery 事件筛选后Fullcalendar事件失去颜色

Jquery 事件筛选后Fullcalendar事件失去颜色,jquery,fullcalendar,Jquery,Fullcalendar,我已经成功地将jquery筛选放在我日历的事件上。但在取消过滤后,事件将失去我为其定义的颜色。你知道怎么改变吗?谢谢大家! $(document).ready(function() { $('#calendar').fullCalendar({ defaultView: 'month', prev: 'left-double-arrow', next: 'right-d

我已经成功地将jquery筛选放在我日历的事件上。但在取消过滤后,事件将失去我为其定义的颜色。你知道怎么改变吗?谢谢大家!

    $(document).ready(function() {
            $('#calendar').fullCalendar({
                defaultView: 'month',
                prev: 'left-double-arrow',
                next: 'right-double-arrow', 
                height: 650, 
                aspectRatio: 2,
                 eventSources: [
                    {   
                        googleCalendarApiKey: GAPI,
                        googleCalendarId: googleCalendarId1,
                        color: '#f25d1d',    
                        textColor: 'white' 
                    }
                ], // To prevent click access to G Calendar
                eventRender: function(event, element) {
                    element.on('click', function (e) {
                        e.preventDefault();
                    });
                },
                 header: {
                    left: '',
                    center:'prev title next',
                    right: 'month,listMonth,'
                }                     
            });

            $("#checkbox1").change(function() {
                if(this.checked) {
                  $('#calendar').fullCalendar( 'addEventSource',  googleCalendarId1 );
                }
                else{
                $('#calendar').fullCalendar( 'removeEventSource',  googleCalendarId1 );
                }
            });
 });

您问题中的代码根本不起作用-简单地将日历ID添加回事件源将导致fullCalendar请求该URL,并返回404。谷歌日历中的事件不会重新添加到日历中。这与您描述的有关颜色的问题无关

无论如何,您肯定也会丢失颜色信息。当您删除事件源时,它将丢失;当您重新添加事件源时,即使您所做的操作可以正常工作,您也不会重新提供包括颜色设置在内的配置信息

显而易见的解决方案是将事件源配置作为单独的对象保存在变量中,然后每次添加和删除该变量。这将保留颜色设置,并使上面的代码正确地重新添加事件源

 var calendar1Source = {
    id: 1,
    googleCalendarApiKey: "SomeAPIKey",
    googleCalendarId: "SomeCalendarID",
    color: '#f25d1d',
    textColor: 'white'
  };

  $('#calendar').fullCalendar({
    header: {
      left: 'prev,next today',
      center: 'title',
      right: 'month,agendaWeek,agendaDay'
    },
    defaultView: 'month',
    eventSources: [calendar1Source],
    // To prevent click access to G Calendar
    eventRender: function(event, element) {
      element.on('click', function(e) {
        e.preventDefault();
      });
    }
  });

  $("#checkbox1").change(function() {
    if (this.checked) {
      $('#calendar').fullCalendar('addEventSource', calendar1Source);
    } else {
      $('#calendar').fullCalendar('removeEventSource', calendar1Source);
    }
  });
请参阅此示例,了解如何使用我碰巧知道的公共日历进行演示: