在完整日历上切换几个月时错误



我对FullCalendar遇到了一个奇怪的问题。当我单击<>按钮,与一次相同的AJAX动作被执行,例如链接上的图像:http://snag.gy/vqfeu.jpg

如果我继续点击,则越来越多的AJAX调用。我的代码是:

$(document).ready(function () {
        var sourceFullView = { url: '/Agenda/GetDiaryEvents/' };
        var sourceSummaryView = { url: '/Agenda/GetDiarySummary/' };
        var CalLoading = true;
        $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            defaultView: 'month',
            editable: true,
            allDaySlot: false,
            selectable: true,
            slotMinutes: 15,
            events: '/Agenda/GetDiaryEvents/',
            eventClick: function (calEvent, jsEvent, view) {
                ClearPopupFormValues();
                $('#eventID').val(calEvent.id);
                $('#eventTitle').val(calEvent.title);
                $('#eventDate').val($.fullCalendar.formatDate(calEvent.start, 'dd/MM/yyyy'));
                $('#eventTime').val($.fullCalendar.formatDate(calEvent.start, 'HH:mm'));
                //Calculando timespan
                var start = new Date(calEvent.start.getFullYear(), calEvent.start.getMonth(), calEvent.start.getDate(), calEvent.start.getHours(), calEvent.start.getMinutes(), 0, 0);
                var end = new Date(calEvent.end.getFullYear(), calEvent.end.getMonth(), calEvent.end.getDate(), calEvent.end.getHours(), calEvent.end.getMinutes(), 0, 0);
                var weeks = 1000 * 60 * 60 * 24 * 7;
                var days = 1000 * 60 * 60 * 24;
                var hours = 1000 * 60 * 60;
                var mins = 1000 * 60;
                var secs = 1000;
                var diffWeeks = Math.ceil((start.getTime() - end.getTime()) / (weeks));
                var diffDays = Math.ceil((start.getTime() - end.getTime()) / (days));
                var diffHours = Math.ceil((start.getTime() - end.getTime()) / (hours));
                var diffMinutes = Math.ceil((start.getTime() - end.getTime()) / (mins));
                var diffSeconds = Math.ceil((start.getTime() - end.getTime()) / (secs));
                $('#eventDuration').val(Math.abs(diffMinutes));
                alert()
                $("#someKey").val(calEvent.someKey);
                $('#popupEventForm').modal('show');
                $('#eventTitle').focus();
                $('#btnPopupDelete').css('display', 'inline');
            },
            eventDrop: function (event, dayDelta, minuteDelta, allDay, revertFunc) {
                if (confirm("Confirma mudança no evento?")) {
                    UpdateEvent(event.id, event.start);
                }
                else {
                    revertFunc();
                }
            },
            eventResize: function (event, dayDelta, minuteDelta, revertFunc) {
                if (confirm("Confirma alteração na duração do evento?")) {
                    UpdateEvent(event.id, event.start, event.end);
                }
                else {
                    revertFunc();
                }
            },
            dayClick: function (date, allDay, jsEvent, view) {
                $('#descricao').val("");
                $('#eventDate').val($.fullCalendar.formatDate(date, 'dd/MM/yyyy'));
                $('#eventTime').val($.fullCalendar.formatDate(date, 'HH:mm'));
                ShowEventPopup(date);
                $('#btnPopupDelete').css('display', 'none');
            },
            eventRender: function (event, element) {
                element.find('.fc-event-time').text($.fullCalendar.formatDate(event.start, 'HH:mm'));
            },

            viewRender: function (view, element) {
                if (!CalLoading) {
                    if (view.name == 'month') {
                        $('#calendar').fullCalendar('removeEventSource', sourceFullView);
                        $('#calendar').fullCalendar('removeEvents');
                        $('#calendar').fullCalendar('addEventSource', sourceSummaryView);
                    }
                    else {
                        $('#calendar').fullCalendar('removeEventSource', sourceSummaryView);
                        $('#calendar').fullCalendar('removeEvents');
                        $('#calendar').fullCalendar('addEventSource', sourceFullView);
                    }
                }
            }
        });
        CalLoading = false;

    });

有人可以帮忙吗?

谢谢

我使用fullcalendar v2.1.1时也有同样的问题LIB中有一个错误,源没有清除,每次点击都会不断增长,因此进行了多个呼叫。作为解决方案,替换demodeventsource(源)用以下代码

替换
function removeEventSource(source) {
    sources = $.grep(sources, function(src) {
        return !isSourcesEqual(src, source);
    });
    // remove all client events from that source
    sources = [];  // this is a bug fix , clear source
    cache = $.grep(cache, function(e) {
        return !isSourcesEqual(e.source, source);
    });
    reportEvents(cache);
}

相关内容

  • 没有找到相关文章

最新更新