在页面上我有fullcalendar,变量决定了现在如何显示(所有事件或带有过滤器的事件),用于更改变量值的按钮和应用过滤器的函数。
变量(true - 显示所有事件,false - 使用过滤器):
var isShownWithCancelEvents = true;
按钮和它的点击功能:
$('.fc-header-left').append('<span class="fc-button fc-button-show-with-canceled-events fc-state-default"><span class="fc-button-inner"><span id="show_without_canceled_events" class="fc-button-content">Show with filter</span><span class="fc-button-effect"><span></span></span></span>');
$(".fc-button-show-with-canceled-events").click(function() {
isShownWithCancelEvents = !isShownWithCancelEvents;
prepareEvents();
});
函数prepareEvents():
function prepareEvents(){
if (isShownWithCancelEvents) {
$('#calendar').fullCalendar('refetchEvents');
$(".fc-button-show-with-canceled-events .fc-button-content ").text("Show with filter");
}
else {
$('#calendar').fullCalendar ( 'removeEvents', filter );
$(".fc-button-show-with-canceled-events .fc-button-content ").text("Show all events");
}
}
过滤功能:
function filter(event) {
return (event.ec_e_id !== null);
}
同样在fullcalendar中我使用选项:
viewDisplay: function(view) {
prepareEvents();
},
按钮正在运行,问题在于fullcalendar选项。
如果我将警报添加到fullcalendar选项
viewDisplay: function(view) {
alert("something");
prepareEvents();
},
一切正常,过滤器每次都有效。