我需要在event函数中传递当前视图类型以及我的ajax url。我正在使用fullcalendar v4.3.1。下面是我的代码,以及我面临的一个问题,即在更改视图时始终获得以前的视图类型。
var currentView = "dayGridMonth";
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'interaction', 'dayGrid', 'timeGrid', 'list' ],
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listMonth'
},
navLinks: true,
businessHours: true,
editable: true,
events: function (info, successCallback, failureCallback) {
jQuery.ajax({
url: '/json/year_plan/get_full_calendar',
type: 'get',
dataType: 'json',
data: {
start: formatDateObjToYMD(info.start),
end: formatDateObjToYMD(info.end),
currentView: currentView
},
success: function(doc) {
var events = [];
$.map( doc, function( r ) {
events.push({
id: r.year_plan_id,
title: r.title,
start: r.start,
end: r.end,
rendering: r.rendering,
color: r.color
});
});
successCallback(events);
}
});
},
viewSkeletonRender: function (info) {
currentView = info.view.type;
},
lazyFetching:false,
});
calendar.render();
});
每次在viewSkeletonRender函数中更改视图时,我都会更新currentView变量。然后我使用事件函数中使用的此更新变量通过ajax发送它。但似乎事件函数先于viewSkeletonRender函数获得调用。