我在fullcalendar中添加了一个搜索功能,当我搜索后,再去点上月按钮,会同时发送搜索的请求,再点击下月或者今天按钮,就会把上次的搜索结果数据也显示在页面上,这是为什么?请问要怎么改?
js代码:
$(document).ready(function() {
var initialLocaleCode = 'zh-cn';
//$('#calendar').fullCalendar('removeEventSources');
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month add edit'
},
defaultDate: moment(),
locale: initialLocaleCode,
buttonIcons: false, // show the prev/next text
weekNumbers: true,
navLinks: true, // can click day/week names to navigate views
editable: true,
eventLimit: true, // allow "more" link when too many events
eventSources: [
// your event source
{
url: '${ctx}${reqmap}calendar2',
type: 'POST',
data:function() { // a function that returns an object
return {
s_BTW_fdDateTime:
$('#calendar').fullCalendar('getDate').startOf('month').format("YYYY-MM-DD")+" 00:00~" + $('#calendar').fullCalendar('getDate').endOf('month').format("YYYY-MM-DD")+" 23:59"
};
},
error: function() {
alert('there was an error while fetching events!');
}
}
]
});
//搜索按钮
$("#btn").click(function(){
var fdNames = $("#s_IN_fdNames").val();
$("#calendar").fullCalendar('removeEvents');
$("#calendar").fullCalendar('addEventSource', {
url: '${ctx}${reqmap}findByGoodsNames',
type: 'post',
data: {
s_BTW_fdDateTime: $('#calendar').fullCalendar('getDate').startOf('month').format("YYYY-MM-DD")+" 00:00~" + $('#calendar').fullCalendar('getDate').endOf('month').format("YYYY-MM-DD")+" 23:59",
fdNames: JSON.stringify(fdNames)
}
});
})
// 刷新按钮
$("#refresh").click(function(){
window.location.reload();
})
});
将$("#calendar").fullCalendar('removeEvents')改为$("#calendar").fullCalendar('removeEventSource');