问题
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