I'm populating an object array from an ajax call using jQuery, in order to display event data from our system into the calendar. For some reason, it won't recognize it as events, and they aren't being displayed on the calendar. See code below.
I've checked it over 100 times, and I'm sure the data is coming in the correct format. The events
variable is also not empty at runtime.
var events = [];
$.ajax({
type: 'GET',
url: "ajax/shared.ashx",
dataType: 'json',
data: 'm=get-staff-schedule',
success: function (json) {
console.log(json);
$.each(json.response.data, function (i, app) {
events.push({
id: app.id,
title: app.ADMIN_NAME,
daysOfWeek: app.day - 1,
startTime: app.time_in,
endTime: app.time_out
});
});
renderCalendar(events);
}
});
function renderCalendar(events) {
var calendarEl = document.getElementById('calendar');
var d = new Date();
var date = d.getFullYear() + '-' + padDigits(d.getMonth() + 1, 2) + '-' + padDigits(d.getDate(), 2)
debugger
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: ['interaction', 'dayGrid', 'timeGrid', 'bootstrap'],
themeSystem: 'bootstrap',
defaultView: 'timeGridWeek',
defaultDate: date,
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
events: events
});
calendar.render();
}
Here is the image of the rendered, blank, calendar. Also, here are FullCalendar's docs for reference: https://fullcalendar.io/docs/event-parsing
replace
events.push({
id: app.id,
title: app.ADMIN_NAME,
daysOfWeek: app.day - 1,
startTime: app.time_in,
endTime: app.time_out
});
by
events.push({
id: app.id,
title: app.ADMIN_NAME,
daysOfWeek: app.day - 1,
start: app.time_in,
end: app.time_out
});
I figured it out! Only took me like 2 hours!
Basically, this object requires all strings. So, the daysOfWeek
value needed to be converted from an integer to a string. Here is what I did:
events.push({
id: app.id,
title: app.ADMIN_NAME,
daysOfWeek: (app.day - 1) + '',
startTime: app.time_in,
endTime: app.time_out
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.