2

我正在使用带有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方法,甚至下拉选择的值已经改变。如何传递下拉控件的当前值并重新加载完整日历?

4

2 回答 2

8

我通过调用fullcalendar的destroy来解决这个问题,如下

$('#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);
        }
    });
}

使用它我解决了问题,但不确定这是正确的方法。即销毁和重新创建日历。我仍在寻找正确的方法

于 2013-05-11T05:45:31.150 回答
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 方法吗?干杯

于 2013-05-10T19:44:31.887 回答