javascript 视图更改时的全日历渲染事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26626509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fullcalendar render event when view is change
提问by PinoyStackOverflower
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?
这段代码的问题在于,即使我已经在议程日视图中,它也会继续调用 eventRender。我怎样才能防止这种情况发生?
回答by Richard L?wenstr?m
Not sure why you would want to do this but here's a working example:
不知道你为什么要这样做,但这里有一个工作示例:
http://jsfiddle.net/3E8nk/762/
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.
请注意,这将在您每次进入议程日时再次添加该事件(尽管这很容易解决)。如果你描述了你真正想做的事情,那么可能有一个更好的解决方案。