Fullcalendar在拖放时复制事件

时间:2015-01-27 13:02:35

标签: javascript jquery fullcalendar

当我将它们拖动到另一个时间段时,我的fullcalendar会直观地复制事件。我已将代码简化为eventDrop以隔离问题,但我无法理解该问题。 如果我将事件存储到我的localStorage,我不会在存储中获得重复,并且当我重新加载页面时,副本会消失。这意味着问题只是视觉问题,而且本身就是完整日历。 然而,这显然是一个巨大的问题,因为我不想重新加载页面:我想留在当前视图中改变我需要的东西。

这是eventDrop的代码:

eventDrop: function(event, delta, revertFunc, jsEvent, ui, view) {
            if (!confirm("Are you sure you want to change " + event.title + " ?")) {
                    /*If the user cancels the change, the event returns to its original position. Otherwise it saves the event.*/

                    revertFunc();       /*Revert changes using the predefined function revertFunc of fullCalendar.*/

                    $("#calendar").fullCalendar("refetchEvents");
                    /*FullCalendar Method to refetch events from all sources and rerender them on the screen.*/

                } else {

                    updateConfirm(event);       /*Use the logic to confirm the event update properties*/

                    Evento.prototype.Update(event);     /*Modify the targeted event on the localStorage using the Update method of the Evento Class*/

                    $("#calendar").fullCalendar("updateEvent", event);
                    /*FullCalendar Method to report changes to an event and render them on the calendar.*/

                    $("#calendar").fullCalendar("refetchEvents");
                    /*FullCalendar Method to refetch events from all sources and rerender them on the screen.*/

                }
            }

这是问题的GIF: https://i.imgur.com/rFPvvjE.gif

更新:在chipstoad的帮助下,我将问题隔离到了我的updateConfirm逻辑:

var updateConfirm = function(event) {
    if (confirm("New title?")) {    /*Check if the user wants to change the event title*/
        event.title = prompt("Enter the new title: ");    /*Set new title for the event*/
    } else {
        event.title = event.title;
    }

    if (confirm("New description?")) {    /*Check if the user wants to change the event description*/
        event.description = prompt("Enter the new description: ");    /*Set new description for the event*/
    } else {
        event.description = event.description;
    }

    if (confirm("Is the event important?")) {   /*Check if the user wants to change the event priority*/
        event.overlap = false;
        event.backgroundColor = "red";    /*Set new priority for the event*/
    } else {
        event.overlap = true;
        event.backgroundColor = "blue";   /*Set new priority for the event*/
    }
};

更新2: <{1}} 之前 updateConfirm(事件):

console.log(event)
在 updateConfirm(事件)之后

Object {id: "2015-01-27T15:29:11+00:00", title: "título", start: m, end: m, allDay: false…}_allDay: false_end: m_id: "2015-01-27T15:29:11+00:00"_start: mallDay: falsebackgroundColor: "blue"className: Array[0]description: "gt4"end: mid: "2015-01-27T15:29:11+00:00"overlap: truesource: Objectstart: mstoringId: "2015-01-27T15:29:11+00:00"title: "título"__proto__: Object

console.log(event)

2 个答案:

答案 0 :(得分:0)

由于该活动不是本地来源的,因此当您致电updateEvent

时,系统会从数据库中重新提取活动,因此无需拨打$("#calendar").fullCalendar("refetchEvents");

我不完全确定为什么它会重复,但由updateEvent修改的事件似乎会持续超过重新提取。您必须更改它的ID或将其替换为另一个事件对象,但我无法重现它。

因此请尝试删除更新行

} else {
    updateConfirm(event); 
    Evento.prototype.Update(event);
    $("#calendar").fullCalendar("refetchEvents");
}

如果这不起作用,请尝试手动删除该事件:

$("#calendar").fullCalendar( 'removeEvents', event._id ) //replace the updateEvent call with this
//or event.id if your events have an explicit id

<强>附录

你可能想要实际找出问题的原因,因为上面只是修补它。 Evento.prototype.Update updateConfirm中的某些内容正在将事件修改为FC认为它是一个不同的事件。它被复制并取代自己吗?你在玩它的身份吗?

答案 1 :(得分:0)

做单例样式的解决方案:

这对我来说停止了由“new Draggable(container)”引起的重复 每次重新加载视图

$scope.Draggable = null  if ($scope.Draggable == null) {
                $scope.Draggable = new Draggable(containerEl, {
                    itemSelector: '.item',
                    eventData: function (eventEl) {
                        return {
                            title: eventEl.innerText
                        };
                    }
                });
            }