简体   繁体   English

Fullcalendar 在拖放时复制事件

[英]Fullcalendar is duplicating event on drag and drop

My fullcalendar duplicates events visually when i drag them to another timeslot.当我将事件拖到另一个时间段时,我的全日历会在视觉上复制事件。 I have simplified my code down to the eventDrop to isolate the issue and yet I'm unable to understand the issue.我已将我的代码简化为 eventDrop 以隔离问题,但我无法理解该问题。 If I store the events to my localStorage I don't get a duplicate in the storage and the duplicate disappears when I reload the page.如果我将事件存储到我的 localStorage 中,我不会在存储中得到重复项,并且当我重新加载页面时,重复项就会消失。 This means the problem is only visual and with Full Calendar itself.这意味着问题只是视觉上的,并且与完整日历本身有关。 However, this is obviously a huge issue as I don't want to reload the page: I want to stay in the current view changing what I need.然而,这显然是一个大问题,因为我不想重新加载页面:我想留在当前视图中更改我需要的内容。

Here's my code for the eventDrop:这是我的 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.*/

                }
            }

And here's a gif of the issue: https://i.imgur.com/rFPvvjE.gif这是问题的 gif: https : //i.imgur.com/rFPvvjE.gif

UPDATE: With slicedtoad's help I isolated the issue to my updateConfirm logic:更新:在 slicedtoad 的帮助下,我将问题隔离到我的 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*/
    }
};

UPDATE 2: console.log(event) before updateConfirm(event):更新 2:updateConfirm(event)之前的console.log(event) (event):

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) after updateConfirm(event): updateConfirm(event)后的console.log(event) event):

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

Since the event is not locally sourced, calling updateEvent isn't necessary since the event will be refetched from the database when you call $("#calendar").fullCalendar("refetchEvents");由于该事件不是本地来源的,因此没有必要调用updateEvent因为当您调用$("#calendar").fullCalendar("refetchEvents");时,将从数据库中重新获取该事件$("#calendar").fullCalendar("refetchEvents");

I'm not entirely sure why it would duplicate but the event modified by updateEvent seems to persist past the refetch.我不完全确定为什么它会重复,但updateEvent修改的事件似乎在重新获取后仍然存在。 You must be changing it's ID or replacing it with another event object, but I wasn't able to reproduce it.您必须更改它的 ID 或将其替换为另一个事件对象,但我无法重现它。

So try removing the update line所以尝试删除更新行

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

If that doesn't work, try deleting the event manually:如果这不起作用,请尝试手动删除事件:

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

Addendum附录

You likely want to actually figure out the cause of the problem since the above just patches it.您可能想真正找出问题的原因,因为上面只是修补了它。 Something in Evento.prototype.Update updateConfirm is modifying the event to the point that FC thinks it is a different event. Evento.prototype.Update updateConfirm中的 Evento.prototype.Update 内容将事件修改为 FC 认为它是不同事件的程度。 Is it being copied and replacing itself?它是否被复制和替换自己? Are you playing with it's id?你在玩它的id吗?

Do singleton style solution:做单例风格的解决方案:

This worked for me to stop the duplication which was caused by "new Draggable(container)" every time reloaded the view这对我有用,可以阻止每次重新加载视图时由“new Draggable(container)”引起的重复

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM