我有以下代码来使用jquery FullCalendar插件:
$(function () {
var dueHotfixEvents = { url: baseUrl + '/Misc/Calendar/GetDueHotfixEvents', color: 'red' };
var releasedHotfixEvents = { url: baseUrl + '/Misc/Calendar/GetReleasedHotfixEvents', color: 'green' };
var releasedVersionEvents = { url: baseUrl + '/Misc/Calendar/GetReleasedVersionEvents', color: 'green' };
var pendingVersionEvents = { url: baseUrl + '/Misc/Calendar/GetPendingReleaseEvents', color: 'blue' };
var dueTaskEvents = { url: baseUrl + '/Misc/Calendar/GetReleaseTasksDueEvents', color: 'red' };
var completedTaskEvents = { url: baseUrl + '/Misc/Calendar/GetReleaseTasksCompletedEvents', color: 'blue' };
$('#calendar').fullCalendar({
//theme: true,
eventSources:
[
dueHotfixEvents,
releasedHotfixEvents,
releasedVersionEvents,
pendingVersionEvents,
dueTaskEvents,
completedTaskEvents
]
});
});
这些会立即检索系统中的所有日期。但是,每当我更改我所在的月份时,它似乎都会重新获取事件源中的所有数据。我不想要这个,因为它已经拥有它需要的所有数据。
文档指出lazyFetching
选项设置为true应该可以解决这个问题,但默认情况下它应该设置为true,但无论是lazyFetching: true,
还是lazyFetching: false,
都没有改变此
如何阻止FullCalendar发出如此多的ajax请求?
答案 0 :(得分:1)
$(function () {
var dueHotfixEvents = { url: baseUrl + '/Misc/Calendar/GetDueHotfixEvents', color: 'red' };
var releasedHotfixEvents = { url: baseUrl + '/Misc/Calendar/GetReleasedHotfixEvents', color: 'green' };
var releasedVersionEvents = { url: baseUrl + '/Misc/Calendar/GetReleasedVersionEvents', color: 'green' };
var pendingVersionEvents = { url: baseUrl + '/Misc/Calendar/GetPendingReleaseEvents', color: 'blue' };
var dueTaskEvents = { url: baseUrl + '/Misc/Calendar/GetReleaseTasksDueEvents', color: 'red' };
var completedTaskEvents = { url: baseUrl + '/Misc/Calendar/GetReleaseTasksCompletedEvents', color: 'blue' };
var eventsLoaded = false;
$('#calendar').fullCalendar({
//theme: true,
eventSources:[],
'viewDisplay': function(v){
if(!eventsLoaded){
var $fcEl = $(this);
$.ajax({
url:dueHotfixEvents.url,
type:"get",
dataType:"json",
success:function(response){
if(response.length > 0) $fcEl.fullCalendar('addEventSource', {events:response,color:dueHotfixEvents.color});
}
});
.
. //do same for every source defined
.
eventsLoaded=true;
}
}
});
});
希望这会对你有所帮助(我想有更好的解决方案,但这个似乎很简单,很容易实现非常快+它很容易包含很多选项来控制,当它适合重新加载事件+它实际上解决了当有定义的在线资源时,我在动态创建事件时不断遇到令人讨厌的双重事件。)