刷新完整日历会添加重复事件

时间:2014-04-15 12:56:08

标签: javascript jquery backbone.js fullcalendar

在第一次加载页面时,它每天显示一个事件,但在第二次加载(或刷新页面)时,它会在完整日历的同一天添加重复事件。

这是我的代码:

var CalendarView = Backbone.View.extend({

    el : '#calendar-box',
    initialize : function() {
    // TODO for instance: more instances, Event Bus bindings... only once.
    this.calendarModel = new CalendarModel();
    $('#calendar-box').hide();
    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    this.calendarModel.fetch({
        success : function(model, response, options) {
            $.unblockUI();
           var count=0;
            var eventsList=[];
            model.attributes.result.forEach(function(){
                eventsList.push({
                    id: model.attributes.result[count].eventId,
                    title:model.attributes.result[count].title,
                    start: new Date(model.attributes.result[count].startDate),
                    end: new Date(model.attributes.result[count].endDate),
                    attorneyName: model.attributes.result[count].attorneyName,
                    codeLitOrg: model.attributes.result[count].codeLitOrg,
                    balance: model.attributes.result[count].balance,
                    litCode: model.attributes.result[count].litCode
                });
                count++;
            });
            if (!_.isEmpty(eventsList)){
                    $('#calendar').fullCalendar({
                        editable: true,
                        events: eventsList,
                        eventMouseover: function(event, jsEvent, view) {
                            var info = event.title+'\nBK/LIT: '+event.codeLitOrg+'\nBalance: '+event.balance
                            +'\nAttorney: '+event.attorneyName+'\nLitCode: '+event.litCode;
                            $(jsEvent.target).attr('title', info);
                        },
                        theme: false,
                        height:575,
                        weekMode:'liquid',
                        header: {
                            left: 'prev,next today',
                            center: 'title',
                            right: 'month,agendaWeek,agendaDay'
                        },
                    });
            }
        },
        error : function(model, xhr, options) {
            $.unblockUI();
        }
    });

    $.eventBus.on('calendarModalLoaded',function(){
        if (!($('.fc-border-separate').html())){
            $('#calendar').fullCalendar('today');
        }           
    });
    },
    render : function() {
        // TODO for instance, bindings elements after ready in DOM.
        $('#calendar').fullCalendar('today');
        return this;
    },
    events : {
        'click a.op-attorney-info' : 'onAttorneyInfo',
        'click .go-back-link' : 'goBack'
    },

    goBack: function(){
        $('#calendar-box, .content-box').toggle();
        //$('.content-box').toggle();
        //$('.go-back-link').hide();
    },

    onAttorneyInfo : function(ev) {
    // TODO for instance, fetch attorney's model
    }
});

return CalendarView;
});

我尝试了$('#calendar').fullCalendar('removeEvents'),但它也无效。 请帮帮我。

0 个答案:

没有答案