如何让Fullcalendar从JSON Feed中缓存事件?
我认为lazyfetching
不符合我的要求。它可以工作一个月。假设我加载一个月,1月,然后更改为日视图,数据被缓存并且不发送ajax请求。但是,如果我将月份更改为2月份并返回1月份,则1月份仍会重新加载。
作者试图accomplish the request back in March of 2011,但仍然不及,我相信。他允许browser possibly cache the result of a request,但这是命中或未命中,取决于浏览器设置。
有什么想法吗?我错过了什么吗?
答案 0 :(得分:3)
我会创建自己的缓存对象,并在fullcalendar初始化程序的events
函数中使用它。此方法使用“事件作为函数”方法来获取事件数据: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
答案 1 :(得分:1)
我通过使用backbone.js和fullcalendar来实现这一目标。 http://blog.shinetech.com/2011/08/05/building-a-shared-calendar-with-backbone-js-and-fullcalendar-a-step-by-step-tutorial/提供代码和解释它的教程。对于您要完成的任务而言,这是一个极端的解决方案,但使用backbone.js和fullcalendar的好处可能值得探索。