问题
How can I get Fullcalendar to cache events from a JSON feed?
I don't think lazyfetching does what I want it to. It works for a single month. Say I load a month, January, and then change to the day view, the data is cached and does not send an ajax request. But If I change months to Feb and back to Jan, January still reloads.
The author attempted to accomplish the request back in March of 2011 but still fell short, I believe. He lets the browser possibly cache the result of a request, but this is hit or miss and depends on browser settings.
Any ideas? Am I missing something?
回答1:
I would make my own caching object and use it in the events
function in the fullcalendar initializer. This method makes use of the "Events as a function" method of getting your event data: http://arshaw.com/fullcalendar/docs/event_data/events_function/
$("#calendar").fullCalendar({
// init options
// go
//here,
events: function (start, end, callback) {
//have we already cached this time?
if (events.eventsCache
&& events.eventsCache[start.toString + "-" + end.toString]){
//if we already have this data, pass it to callback()
callback(eventsCache[start.toString + "-" + end.toString]);
return;
}
//we haven't gotten this time range (month) yet. get it, and pass it to callback()
$.get("where_my_events_live.php", function(data){
if (!events.eventsCache)
events.eventsCache = {};
//store your data
eventsCache[start.toString + "-" + end.toString] = data;
callback(data);
});
},
..r
回答2:
I accomplish this by using backbone.js with fullcalendar. http://blog.shinetech.com/2011/08/05/building-a-shared-calendar-with-backbone-js-and-fullcalendar-a-step-by-step-tutorial/ provides code and a tutorial explaining it. It's a bit of an extreme solution for what you're asking to accomplish but the benefits of using backbone.js with fullcalendar may be worth exploring.
来源:https://stackoverflow.com/questions/8858426/fullcalendar-json-feed-caching