简体   繁体   中英

fullcalendar.io - Holding Event in memory

I believe javascript is holding the event in memmory but I can't figure out where and how to get around it. maybe you guys can help. I have created a JSFiddle to demonstrate the problem

JSFIDDLE

So it happens when you update one event. Then you move to another event go to update that event. It brings the old event to the new event. Changes the start and end and everything. First event updates fine.

When you click event. These functions are fired.

function eventClick(calEvent){
    $('#edit-event-title').val(calEvent.code);
    $('#edit-event-description').val(calEvent.description);
    $('#event-start-edit-dpick').data('DateTimePicker').date(calEvent.start).format('YYYY-MM-DD');
    $('#event-start-time-edit-dpick').data('DateTimePicker').date(calEvent.start).format('HH:mm');
    $('#event-end-edit-dpick').data('DateTimePicker').date(calEvent.end).format('YYYY-MM-DD');
    $('#event-end-time-edit-dpick').data('DateTimePicker').date(calEvent.end).format('HH:mm');
    $('#fc_edit').click();
}


function createUpdateEvent(calEvent, create) {
        //create event
        if(create){
            // create the event
        } else {
            $(".antosubmit2").on("click", function() {
                calEvent.code = $("#edit-event-title").val();
                calEvent.title = $("#edit-event-title option:selected").html();
                calEvent.description = $("#edit-event-description").val();
                calEvent.start = moment($('#event-start-edit-dpick').data('DateTimePicker').date().format('YYYY-MM-DD') + ' ' +
                $('#event-start-time-edit-dpick').data('DateTimePicker').date().format('HH:mm') +
                $('#event-start-edit-dpick').data('DateTimePicker').date().format('Z'));
                calEvent.end = moment($('#event-end-edit-dpick').data('DateTimePicker').date().format('YYYY-MM-DD') + ' ' +
                $('#event-end-time-edit-dpick').data('DateTimePicker').date().format('HH:mm') +
                $('#event-end-edit-dpick').data('DateTimePicker').date().format('Z'));
                calendar.fullCalendar('updateEvent', calEvent);

                $('.antoclose').click();
            });
        }

    }

function recalcHeaderHours(event){
        var currentday = moment(event.start).format("YYYY-MM-DD");
        if (event.totalHours > 0) {
            var prev = $("#dailytotal-"+currentday).text() || 0;
            $("#dailytotal-"+currentday).text(+prev + +event.totalHours);
        }
    }

I hope you guys can assist. Thanks for your time :)

I fixed your issue. The problem is that you put the on click event to the ".antosubmit2" in line 83. On first event open there will be 1 click on this class, but on the 2. event open the code put another click on it. If you open only one event 2 times, there will be no problem. But it you do it on different events, on the second open, 2 click fires on it. The newly added click use correct data, but the first click use the first event datas. This is your problem I guess. The first click should be unbind from the ".antosubmit2". Try to modify your code like this:

function createUpdateEvent(calEvent, create) {
    //create event
    if(create){
        // create the event
    } else {
        $(".antosubmit2").unbind('click');
        $(".antosubmit2").on("click", function() {...

You see the "unbind('click')" line, add it to the code and it will works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM