|
Hello all
I have a JavaScript based calendar " FullCalendar V5 / https://fullcalendar.io/docs/v3/events-function "
which I build in Java via script.
So far no problem, but now I want to display my events dynamically/ fetch them from
the DB depending on the custom filter
One option I saw in the doc is to fetch the events via function,
which is called whenever the calendar needs new dates/events,
Example from doc:
THE OLD VERSION
$('#calendar').fullCalendar({
events: function(start, end, timezone, callback) {
$.ajax({
url: 'myxmlfeed.php',
dataType: 'xml',
data: {
// our hypothetical feed requires UNIX timestamps
start: start.unix(),
end: end.unix()
},
success: function(doc) {
var events = [];
$(doc).find('event').each(function() {
events.push({
title: $(this).attr('title'),
start: $(this).attr('start') // will be parsed
});
});
callback(events);
}
});
}
});
THE NEW VERSION
import { req } from 'superagent'; // ajax library
var calendar = new Calendar(calendarEl, {
events: function(info, successCallback, failureCallback) {
req.get('myxmlfeed.php')
.type('xml')
.query({
start: info.start.valueOf(),
end: info.end.valueOf()
})
.end(function(err, res) {
if (err) {
failureCallback(err);
} else {
successCallback(
Array.prototype.slice.call( // convert to array
res.getElementsByTagName('event')
).map(function(eventEl) {
return {
title: eventEl.getAttribute('title'),
start: eventEl.getAttribute('start')
}
})
)
}
})
}
});
My question now is, how do I build the URL so that I can call
an action method, perhaps with parameters, in my component?
Or maybe you have a better idea how to do this:)
Many Thanks
Michele
|
|