我正在使用http://arshaw.com/fullcalendar/,我想根据页面上的各种复选框动态过滤所显示的事件。我正在使用ajax源(带有作为参数传递的过滤器)来收集数据。
我遇到的问题是,一旦我加载日历,我不能,因为我的生活(或stackoverflow搜索)找出如何更新参数。一旦加载日历,这些参数就会被“烘焙”并且无法更改。
我已尝试过addEventSource,removeEventSources,removeEvents,refetchEvents等的所有组合(如此处所建议:rerenderEvents / refetchEvents problem),但仍然没有运气。
我目前的解决方案是每次更新过滤器时重新启动整个.fullCalendar--这也导致了大量问题,而且实际上并不是一个优雅的解决方案。
有关更简单方法的任何想法吗?每次使用更新的参数重新获取源应该是自动的。我非常感谢你的帮助。
答案 0 :(得分:0)
在我的代码中,我喜欢这样:
我有一个显示日历id的数组,当用户选中或取消选中该复选框时,我会更新它。
在fullCalendar初始化中,我检索所有事件,并使用此函数过滤它们:
function fetchEvent( calendars, events) {
function eventCorrespond (element, index, array) {
return $.inArray(element.calendarid, calendars) > -1;
}
return events.filter(eventCorrespond);
}
$('#calendar').fullCalendar({
events: function(start, end, callback) {
//fetch events for date range on the server and retrieve an events array
//update calendars, your array of calendarsId
//return a filtered events array
callback(fetchEvent(calendars , events));
}
});
当用户选中或取消选中复选框时,我会执行以下操作:
$('#calendar').fullCalendar('refetchEvents');
答案 1 :(得分:0)
对我有用的解决方案是:
$('#calendar').fullCalendar('removeEventSource', 'JsonResponse.ashx?technicans=' + technicians);
technicians = new_technicians_value;
$('#calendar').fullCalendar('addEventSource', 'JsonResponse.ashx?technicans=' + technicians);
“addEventSource”事件将立即从新源获取。