javascript - Fullcalendar 在拖放时复制事件

标签 javascript jquery fullcalendar

当我将事件拖到另一个时间段时,我的全日历会在视觉上复制事件。我已将我的代码简化为 eventDrop 以隔离问题,但我无法理解该问题。 如果我将事件存储到我的 localStorage,我不会在存储中获得重复项,并且在我重新加载页面时重复项会消失。这意味着问题只是视觉上的,并且与完整日历本身有关。 然而,这显然是一个大问题,因为我不想重新加载页面:我想留在当前 View 中更改我需要的内容。

这是我的 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.*/

                }
            }

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

更新:在 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*/
    }
};

更新 2: console.log(event) 之前 updateConfirm(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):

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

最佳答案

由于事件不是本地来源,调用 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 认为它是不同事件的程度。它正在被复制和替换吗?你在玩它的 ID 吗?

关于javascript - Fullcalendar 在拖放时复制事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28171188/

相关文章:

javascript - fullcalendar v5.9 中每个资源的标题颜色不同

javascript - Ajax函数不调用Servlet

javascript - 如何在前端 Node js 中获取重置密码 api

javascript - 如何在 <hr> 上制作小箭头按钮(用于 JQuery 的 slideUp/slideDown)

jquery - 完整日历 + 事件 + 事件 Drop + Ajax - 不发送日期值

jquery - 使用 Node js 和 mysql 的 Fullcalendar

javascript - 如何不使用每个 jquery 复制数组?

javascript - JavaScript 中的装饰函数

javascript - jQuery 显示/隐藏方法不起作用

jquery - 如何排除 jQuery DataTable 中的最后一列