我正在使用带有json feed的fullcalendar,代码如下
$('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events: {
url: '/EventInfo/GetEventsByEmployee',
cache: false,
lazyFetching:true,
type: 'POST',
data: {
empId: $('#eventownerId').val()
},
error: function () {
alert('there was an error while fetching events!');
},
},
dayClick: function (date, allDay, jsEvent, view) {
displayDayEvents(date, allDay, jsEvent, view);
},
eventRender: function (event, element) {
element.find('.fc-event-time').hide();
element.attr('title', event.tip);
}
});
这里我通过数据字段将下拉控件的选定值传递为“empId:$('#eventownerId')。val()”。它在页面加载时返回正确的数据。 现在,当用户从下拉列表中选择选项时,我想重新加载日历数据。 为此我使用了以下代码
$('#eventownerId').change(function (e) {
$('#calendar').fullCalendar('removeEvents');
$('#calendar').fullCalendar('refetchEvents');
});
但是refetch用旧数据调用json方法(即下拉控制的初始值),甚至选择的下拉值也已经改变。 我如何传递下拉控件的当前值并重新加载fullcalendar?
答案 0 :(得分:8)
我通过调用destroy of fullcalendar来解决问题,如下所示
$('#dropdownlistId').change(function (e) {
$('#calendar').fullCalendar('destroy');
RenderCalendar($(this).val());
});
和RenderCalendar()是
function RenderCalendar(eId) {
$('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events: {
url: '/EventInfo/GetEventsByEmployee',
cache: true,
type: 'POST',
data: {
empId: eId
},
error: function () {
alert('there was an error while fetching events!');
},
},
dayClick: function (date, allDay, jsEvent, view) {
displayDayEvents(date, allDay, jsEvent, view);
},
eventRender: function (event, element) {
element.find('.fc-event-time').hide();
element.attr('title', event.tip);
}
});
}
使用这个我解决了问题,但不确定这是否正确。即破坏和重新创建日历。我仍在寻找正确的方法
答案 1 :(得分:0)
你试过在var中获取id然后这样做吗?
var id = $('#eventownerId').val(); //outside
$('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events: {
url: '/EventInfo/GetEventsByEmployee',
cache: false,
lazyFetching:true,
type: 'POST',
data: {
empId: id // var in here
},
error: function () {
alert('there was an error while fetching events!');
},
},
dayClick: function (date, allDay, jsEvent, view) {
displayDayEvents(date, allDay, jsEvent, view);
},
eventRender: function (event, element) {
element.find('.fc-event-time').hide();
element.attr('title', event.tip);
}
});
另一件事是检查ID是否实际上从下拉列表中获取了不同的ID。你能展示一下GetEventsByEmployee方法吗?干杯