我有两个来自引导程序的选项卡。Fullcalendar 在默认隐藏的第二个选项卡内。所以我使用onclick事件来触发该calendar_view_session
功能。但是每次我访问该选项卡时,新日历都会附加到相同的选项卡中。它实际上是在复制日历。
calendar_view_session: function(){
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'dayGrid', 'timeGrid', 'list', 'interaction' , 'momentTimezone' ],
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
},
defaultDate: '2019-04-12',
navLinks: true, // can click day/week names to navigate views
editable: false,
eventLimit: true, // allow "more" link when too many events
events: function(info, successCallback,failureCallback) {
console.log(info);
var date1 = new Date(info.start.valueOf());
var date2 = new Date(info.end.valueOf());
var callData = {
from_date:moment.tz(date1, timeZone).format('YYYY-MM-DD'),
to_date: moment.tz(date2, timeZone).format('YYYY-MM-DD')
}
sessionCalendar = [];
console.log(callData);
$.ajax({
url:app.createApiPath(apiController_data,apiAction_data),
method:"POST",
dataType: "json",
data: {
callData: JSON.parse(JSON.stringify(callData)),
api_version: 1,
deviceType: 'web'
},
success: function(responseData){
console.log({responseData})
successCallback(app.calendarParse(responseData.data.results));
}
})
},
//sessionCalendar
});
calendar.render();
},
我的 HTML 代码
<div>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#list_view_session" aria-controls="list_view_session" role="tab" data-toggle="tab">List View</a></li>
<li role="presentation"><a href="#calendar_view_session" id="calendar_view_session_id" onclick="app.calendar_view_session()" aria-controls="calendar_view_session" role="tab" data-toggle="tab">Calendar View</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="list_view_session">
<div class="session_list">
<div class="loaderapi hide">
<i class="fa fa-spinner fa-spin fa-4x" aria-hidden="true"></i>
</div>
</div>
</div>
<div role="tabpanel" class="tab-pane" id="calendar_view_session">
<div id='calendar'></div>
</div>
</div>
</div>
这是我的功能。但是,我$("#calendar").destroy()
首先使用函数来销毁日历。它显示错误说
sessions.js:253 Uncaught TypeError: $(...).destroy is not a function
我之后使用这个破坏功能
var calendarEl = document.getElementById('calendar');
线。