JQuery Full Calendar-初始化后编辑日历视图



在脚本的开头,我有许多选项传递给日历。

初始化后,执行以下操作不会更改现有日历的视图,但会创建一个新日历

$('.calendar-container').fullCalendar({
   defaultView: 'agendaWeek'
});

问题:如何更改.calendar-containerdiv中已存在的日历视图?

FullCalendar只支持在初始化后更改一些选项,如height、contentHeight和aspectRatio。如果要更改其他选项,则应销毁当前日历,然后使用新选项再次初始化FullCalendar。

您可能需要记住当前状态,以便在日历被销毁后重新创建它。将此回调包含在FullCalendar选项中,并将视图保存在日历销毁后可以访问的某个变量中:

viewDisplay: function(view) {
    latestView = view;
}

然后,您可以在重新初始化日历后调用这些方法,并重新创建日历所处的状态(如相同的视图和日期范围):

$("#calendar").fullCalendar('changeView', latestView.name);
$("#calendar").fullCalendar('gotoDate', latestView.start);

如果您浏览他们的文档,就会清楚地指定它。

有一个功能可以更改视图。

.fullCalendar( 'changeView', viewName )

http://arshaw.com/fullcalendar/docs/views/changeView/

想象一下您想要更改事件源。。。。

function getSources(switcher){    
        if(switcher== "option1"){
            return [othersources.opt1,othersources.opt2];
        }else{
            if(switcher== "option2"){                       
            return [othersources.opt3];}
        }      
    }

...
eventSources: getSources(switcher),
...

你可以找到一种方法,用一个简单的函数来更改任何属性。。。

希望它能帮助。。。

最新更新