FullCalendar不会取消选择以前的选择

时间:2017-09-05 02:51:35

标签: javascript jquery fullcalendar

我最近一直在使用FullCalendar来预订系统。 问题是每当我选择一个时间范围时,它都会添加到eventData对象中。我想要做的只是选择一个时间范围。

当我点击$('#btn-reserve')按钮时,它应该在日历上呈现事件。

正在发生的事情是,即使我之前的选择也会在日历上呈现。我只想渲染我做的最后一个选择。

这是我的代码

$('.calendar').fullCalendar({
    selectable: true,
    select: function(start, end) {
            $('#end_time').val(end);
            $('#start_time').val(start);
            $('#newScheduleModal').modal({
                show : true,
                backdrop: 'static',
                keyboard: false
            });

            $('#btn-reserve').click(function(){
                    eventData = {
                        title: 'Lesson Schedule',
                        start: start,
                        end: end
                    };
                    $('.calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
                    $('#newScheduleModal').modal('hide');
            });

            $('#btn-cancel-reserve').click(function(){
                $('.calendar').fullCalendar('unselect');
                eventData = {};
            })
    },

})

1 个答案:

答案 0 :(得分:1)

每次选择日历时,您都会添加新的点击事件。您需要在添加之前取消绑定点击,如下所示:

 $('#btn-reserve').off('click').click(function

您可能希望为您的"#btn-cancel-reserve"做同样的事情。元件。