Fullcalendar:丢弃时重复输入(外部)

时间:2015-06-25 11:14:49

标签: javascript jquery drag-and-drop fullcalendar

我使用while adding events to Fullcalendar by external drag and drop, item doesn't get id来修改已删除的元素(标题,ID和日期),并在fullcalendar的drop函数中获取回调

var url = "json-save-urlaub.php?event="+date.format()+"&allDay="+date.hasTime();
                    $.post(
                        url, 
                        function(data){ //callback function retrieving the response sent by the controller/action
                            //event is the object that will actually be rendered to the calendar
                            var event = jQuery.parseJSON(data);
                            //actually rendering the new event to the calendar

                            $('#calendar').fullCalendar('renderEvent', event, true);

                            //$('#calendar').fullCalendar('refetchEvents');
                            $('#calendar').fullCalendar('unselect');
                        }
                    );

但是现在当我将元素放在fullcalendar上时我有两个条目,因为回调给了我一个新的事件对象而丢弃的那个我无法删除,因为它没有id而且我无法手动删除它也不能我用它来进行URL调用。

$(this).remove();无效。首先复制已删除的元素时,$("#calendar").fullCalendar( 'removeEvents', copiedEventObject._id);都没有。放弃它时如何才能有一个元素?

1 个答案:

答案 0 :(得分:3)

根据renderEvent

的FullCalendar文档
  

“通常,一旦日历重新获取其事件源(例如:单击prev / next时),事件将消失。但是,将stick指定为true将导致事件永久固定到日历。”

创建对象时,需要在对象数据中设置不粘。即。 stick: false,或者只是删除stick: true

    $('#external-events .fc-event').each(function() {

        // store data so the calendar knows to render an event upon drop
        $(this).data('event', {
            title: $.trim($(this).text()), // use the element's text as the event title
            stick: false // (see docs on the renderEvent method)
        });

        // make the event draggable using jQuery UI
        $(this).draggable({
            zIndex: 999,
            revert: true,      // will cause the event to go back to its
            revertDuration: 0  //  original position after the drag
        });

    });
相关问题