Reputation: 11
I'm having an issue with using calendar.getEvents() within the loading function. In v3 the code looked like this:
$('##calendar').fullCalendar({
...,
events: {
url: 'myurl',
...
},
loading: function(bool) {
$('##loading').toggle(bool);
if (!bool) {
var eventview = $('##calendar').fullCalendar('getView');
var loadedEvents = $('##calendar').fullCalendar('clientEvents', function(events){ return (moment(events.start).format('YYYY-MM-DD') >= eventview.start.format('YYYY-MM-DD') && eventview.end.format('YYYY-MM-DD') > moment(events.start).format('YYYY-MM-DD'))});
for (i = 0; i < loadedEvents.length; i++) {
... // I inventory the type of events in the current month here
};
}, ... }
and now with v5 it looks like this:
"var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
...,
eventSources: [{
url: 'myurl',
...
}],
loading: function(bool) {
if (!bool) {
var eventview = calendar.view;
var loadedEventTypes = new Array();
var loadedEventTypesHTML = ''; var loadedEventTypesStyles = '';
var loadedEvents = calendar.getEvents(); // filter removed for debugging
for (i = 0; i < loadedEvents.length; i++) {
...
};
},
... }
While the docs say that in v3 clientEvents and in v4/5 getEvents both " ... return an array of Event Objects that FullCalendar has stored in client-side memory." that's not what I'm seeing.
In the v3 code clientEvents does retrieve the events just loaded via the JSON url however in v5 getEvents is returning the the event array before loading the json via the url provided; the getEvents event set does not include the JSON just loaded ( and on display). It does holds events fetched before the last json call. The first time the page loads the array is empty even though the events are on display in the calendar.
Does anyone have any suggestions on how to get at the events just loaded and on display in v5.
Is this a bug in FullCalendar?
Upvotes: 1
Views: 1126
Reputation: 316
If you want to do something with your events after load, I think you should take a look at Event Render Hooks and more over at eventDidMount instead of loading.
Upvotes: 2