jquery - 将事件添加到 FullCalendar 时,它们会重复 - 无故多次调用添加事件

标签 jquery events fullcalendar addition

我正在使用 FullCallendar 和 Jquery。我制作了一个类似谷歌日历的界面,并从 json 文件中提取事件。当用户单击某一天时,将打开一个 div 供他们输入信息,然后单击添加事件并添加该事件。当用户单击添加事件时,第二次单击时会添加两个事件,一个在第一次单击的日期,第二个在选定的日期。第三次单击时,将添加 3 个事件,依此类推。这是代码: var c = 0;

function cleanEventBubble(){
    $('#event').hide();
    $('td').removeClass('selDay');
    $('#eventDate').text('');
    $('#calEvent,input:text').val('');
}

function createEvent(date, allDay, jsEvent, View, selCell){
    //Clean the event bubble and calendar
    cleanEventBubble();
    $(selCell).addClass('selDay');
    $('#eventDate').append(date.toDateString());
    $('#event').css('left', jsEvent.pageX);
    $('#event').css('top', jsEvent.pageY);
    $('#event').show();

    $('#btnAddEvent').click(function(){addEvent(date, $('#title').val(), c)});
}

function addEvent(date, title, id){
    $.ajax({
            type:'get',
    <cfoutput>url:  '#strURL#'</cfoutput>,
            data:{
                method:'addEvent',
                user:1,
                title:title,
                allDay:'true',
                start:$.fullCalendar.formatDate( date, 'yyyy-MM-dd' )
                },
            dataType:   'json',
            success: function(data, status){alert('response: ' + data);},
            error: function(data){$('#returnMess').html(data);}

    });
    $('#calendar').fullCalendar( 'refetchEvents' )
    cleanEventBubble();
}

/**/
function removeEvent(id){
    $('#calendar').fullCalendar('removeEvents', id);
}

function updateEvent(id, title){
    var event = $('#calendar').fullCalendar('clientEvents', id);
    event.title = title;
    $('#calendar').fullCalendar('updateEvent', event);
}


$(document).ready(function() {
    //Create JQuery connection to obj
    $('#event').hide();
    //Make event bubble draggable
    $('#event').draggable();

    $('#evBubbleClose').click(cleanEventBubble);
    // page is now ready, initialize the calendar...
    $('#calendar').fullCalendar({
        // put your options and callbacks here date, allDay, jsEvent, view
        dayClick:function(date, allDay, jsEvent, view){
           createEvent(date, allDay, jsEvent, view, this);
        },
        <cfoutput>events: '#strURL#'+'?wsdl&method=getEvents'</cfoutput> ,
        theme: true,
        header: {left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' }, 
        editable:true
    });

    //$('#calendar').fullCalendar('renderEvents');

});

最佳答案

好的,这是没有 bool 标志的解决方案:)

而不是$(this).remove();

使用

$('#calendar').fullCalendar( 'removeEvents', event.id );

See documentation

关于jquery - 将事件添加到 FullCalendar 时,它们会重复 - 无故多次调用添加事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3786729/

相关文章:

java - 如何在 JNI 中将事件/信号从 C 发送到 Java

javascript - 如何在 Fullcalendar 中同时显示背景渲染和事件背景?

javascript - 是否可以使用 <span> 中的值作为 Ruby 函数的参数?

jquery - 如何使用 Jquery 设置非标准的 css 属性?

javascript - 如何显示过去 3 个月的数据?

javascript onmouseout 应用于由 child 触发的 div

javascript - 如何在 webpack.config.js 中包含全日历语言环境

javascript - 如何使用箭头键在gridview中转到不同的文本框

jquery - Tomcat CORS 过滤器和 Spring Security

android - 如何检测 Android 上的触摸输入