2

我正在使用 FullCalendar 显示事件,我通过一个进行 AJAX 调用的 javascript 函数来获取这些事件。这样做是为了发送一个限制器,限制在给定的一天传回多少事件,包括 ViewMore 选项。

通过关闭lazyFetching,结果似乎是FullCalendar 对页面上触发的每个事件进行重新渲染。这导致它每次都执行新的 AJAX 调用。

如何防止 FullCalendar 进行这些不必要的 AJAX 调用?

下面是初始化我的 fullCalendar 的代码。谢谢!

    $('#calendar').fullCalendar({
    defaultView: 'basicWeek',
    theme: true,
    isRTL: isRightToLeft,
    contentHeight: 800,
    weekends: true,
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,basicWeek,basicDay'
    },
    lazyFetching: false,
    columnFormat: {
        month: 'ddd',
        week: 'ddd ' + shortMonthDayPattern,
        day: 'dddd ' + shortMonthDayPattern
    },
    titleFormat: {
        month: yearMonthPattern,                             // September 2009
        week: "MMM d[ yyyy]{ '—'[ MMM] d yyyy}", // Sep 7 - 13 2009
        day: longDatePattern                  // Tuesday, Sep 8, 2009
    },
    dayClick: function (date, allDay, jsEvent, view) {
        if (view.name != 'basicDay') {
            $('#calendar').fullCalendar('changeView', 'basicDay');
            $('#calendar').fullCalendar('gotoDate', date);
        }
    },
    eventClick: function (event, jsEvent, view) {
        if (event.id === "viewMore") {
            $('#calendar').fullCalendar('changeView', 'basicDay');
            $('#calendar').fullCalendar('gotoDate', event.start);
        }
        else {
            navigateBackboneCal(event.id);
        }
    },
    editable: false,
    loading: function (isLoading) {
        if (isLoading) {
            $('.fc-content').block({
                message: null,
                css: { top: '10' }
            });
        }
        else {
            $('.fc-content').unblock();
        }
    },
    viewDisplay: function (view) {

    },
    events: function (startDt, endDt, callback) {
        var maxEvents = 0;
        var view = $('#calendar').fullCalendar('getView');
        if (view.name === 'month')
            maxEvents = 5;
        else if (view.name === 'basicWeek')
            maxEvents = 30;

        var events = [];
        $.ajax({
            url: '/GetCalendarEvents',
            type: 'POST',
            data: { start: Math.round(startDt.getTime() / 1000), end: Math.round(endDt.getTime() / 1000), maxEvents: maxEvents },
            error: function (error) {
                alert('There was an error while fetching events!');
                $('.fc-content').unblock();
            },
            success: function (result) {
                if (result.viewMoreEvents)
                    events = $.merge(result.events, result.viewMoreEvents);
                callback(events);
            }
        });


    }
});
4

0 回答 0