使用removeEvents方法删除特定事件

wow*_*uzz 7 javascript jquery fullcalendar

我刚刚开始使用这个插件,我在删除刚刚创建的事件时遇到了一些麻烦.我可以在使用eventClick时删除所有事件,但不能在eventClick上删除特定事件.

任何帮助,将不胜感激.这是我的代码.

<script type='text/javascript'>

$(document).ready(function() {

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    var calendar = $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        selectable: true,
        selectHelper: true,
        select: function(start, end, allDay) {
            var title = prompt('Trade Show Name:');
            if (title) {
                calendar.fullCalendar('renderEvent',
                    {
                        title: title,
                        start: start,
                        end: end,
                        allDay: allDay,
                        id: 12
                    },
                    true // make the event "stick"
                );
            $('input[name="startDate"]').val(start);
            }
            calendar.fullCalendar('unselect');
        },
        eventClick: function(calEvent, jsEvent, view) {
            $('#calendar').fullCalendar('removeEvents', function (calEvent) {
                return true;
            });,
        editable: true
    });

});
Run Code Online (Sandbox Code Playgroud)

gan*_*shk 25

您可以通过两种方式执行此操作:

1)为每个事件设置唯一ID,并将这些ID传递给removeEvents呼叫.

eventClick: function (calEvent, jsEvent, view) {           
    $('#calendar').fullCalendar('removeEvents', calEvent._id);
}
Run Code Online (Sandbox Code Playgroud)

_id是fullCalendar生成的唯一ID.

2)通过过滤功能删除所需的事件.

考虑到你正试图这样做eventClick,我建议你使用第二个.您的案例如下:

eventClick: function (calEvent, jsEvent, view) {
    $('#calendar').fullCalendar('removeEvents', function (calEvent) {
        return true;
    });
}
Run Code Online (Sandbox Code Playgroud)

传递过滤函数以removeEvents接受您要删除的事件并返回true.既然你正在这样做eventClick,你所要做的就是通过calEvent.

希望这可以帮助!