Fullcalendar:为什么日历在页面上出现两次?

我正在使用Fullcalendar for jQuery,由于某种原因,日历在页面上出现两次。 这不是关于在同一页面上有两个fullcalendar实例的问题。

相反,在第一个日历的底部,存在第二个相同的日历。

我确认我的页面中只有一个#calendar div,所以错误与调用fullcalendar.js的.js有关,我相信。

任何帮助非常感谢。

JS代码:

jQuery('#calendar').fullCalendar({ year: jQuery.today.getFullYear(), month: jQuery.today.getMonth(), date: jQuery.today.getDate(), theme: true, contentHeight: 1000, header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' }, defaultView: 'agendaDay', dayClick: function(date, allDay, jsEvent, view) { // a lot of custom code } }); 

HTML:

 

javascript中对fullcalendar的其他调用(这会将一个datepicker放在同一页面上#calendar div左边的div中):

 jQuery('#datepicker_for_calendar').datepicker({ defaultDate: jQuery.today, minDate: jQuery.startDate, maxDate: jQuery.endDate, inline: true, showButtonPanel: true, onSelect: function(dateText, inst) { var d = new Date(dateText); jQuery('#calendar').fullCalendar('gotoDate', d); selectedDate = d; } }); 

添加a.html(''); 在缩小版本中运行f()
我在一个对话框中打开了我,每次点击一个按钮打开就会有另一个日历。
经过一些阅读后,我找到了使用的方法 – .fullCalendar('destroy') – 这样你就不需要编辑插件了。
现在,关闭对话框并重新打开后,只显示一个日历。

我最近遇到了同样的问题并尝试了一下()jQuery插件,这对我来说不起作用。 但是,我重新下载了非缩小源,并在initialRender方法中添加了以下行作为方法的第一行,它解决了我的重复日历方法。

element.html('');

我的猜测是我的问题来自这样一个事实,即我在没有刷新页面的情况下重新初始化日历,这似乎是js代码不断地将日历附加到现有div而不清除现有日历。

好的,经过长达一周的bug测试后,我找到了这个jQuery插件:

一旦()

http://plugins.jquery.com/project/once

一旦在.fullcalendar之前应用于#calendar div,问题就解决了,只渲染了一个日历。

工作代码:

 jQuery('#calendar').once('calendar').fullCalendar({ 

……})

这应该做这个技巧http://api.jquery.com/one 。

所以类似于@netefficacy(使用一个而不是一次 ):

$('#calendar').one('calendar').fullCalendar({...})