Fullcalendar render event when view is change

大憨熊 提交于 2019-12-11 03:23:54

问题


I have this code

$('#calendar').fullCalendar({
    viewRender:function(view,element){
        if(view.name == "agendaDay"){
            if(jQuery("#calendar").hasClass("hasRendered") == false){
                var newEvent = {
                    start: '2014-10-29 07:00',
                    end: '2014-10-29 10:00',
                    allDay: false,
                };
                $('#calendar').fullCalendar( 'renderEvent', newEvent,'stick');
            }

        }
    },
});

The problem with this code is that it keeps on calling the eventRender even if I am already in the agendaDay view. How can I prevent that one to happen?


回答1:


Not sure why you would want to do this but here's a working example:

http://jsfiddle.net/3E8nk/762/

viewRender:(function() {

    var lastViewName;
    return function(view, element) {

        if(view.name === 'agendaDay' && lastViewName != view.name) {

            var newEvent = {
                start: '2014-06-12T10:30:00',
                end: '2014-06-12T12:30:00',
                allDay: false,
                title: 'My test meeting'
            };
            $('#calendar').fullCalendar( 'renderEvent', newEvent);
        }

        lastViewName = view.name;
    }
})(),

Note that this will add the event again every time you go to agendaDay (this can easily be remedied though). If you describe what you actually want to do there's probably a better solution for all this.



来源:https://stackoverflow.com/questions/26626509/fullcalendar-render-event-when-view-is-change

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