2012-01-13 65 views
3

我怎樣才能讓Fullcalendar緩存來自JSON供稿的事件?Fullcalendar JSON供稿緩存

我不認爲lazyfetching做我想要的。它工作一個月。假設我加載了一個月,一月,然後切換到日視圖,數據被緩存,並且不發送ajax請求。但如果我將月份更改爲2月份並回到1月份,1月份仍會重新加載。

作者試圖accomplish the request back in March of 2011但我相信仍然不足。他讓browser possibly cache the result of a request,但這是擊中或錯過,並取決於瀏覽器設置。

任何想法?我錯過了什麼嗎?

回答

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