jQuery 通过拖放 fullcalendar-Javascript 更新事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19434303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:57:05  来源:igfitidea点击:

updating an event by dragging/dropping fullcalendar- Javascript

javascriptjqueryfullcalendar

提问by cybertextron

I'm using Fullcalendarfor a project I'm developing ... I have only one feature left to be implemented, which is when an existing event is dragged from it's original position to another time or date. I would like to know how I get the current object information (title, new start time, old start time, id, url, etc), so I can update the database with the newer information ... which property from the Fullcalendar object do I use? I implemented the dropproperty;

我正在将Fullcalendar用于我正在开发的项目......我只剩下一个功能需要实现,那就是将现有事件从其原始位置拖到另一个时间或日期。我想知道如何获取当前对象信息(标题、新开始时间、旧开始时间、id、url 等),以便我可以使用较新的信息更新数据库...... Fullcalendar 对象中的哪些属性可以我用?我实现了该drop属性;

    drop  : function(date, allDay) {
            // retrieve the dropped element's stored event object
            var originalEventObject = $(this).data('eventObject');
            // we need to copy it, so that multiple events don't 
            // have a reference object
            var copiedEventObject   = $.extend({}, originalEventObject);
            // assign it the date that was reported
            copiedEventObject.start = date;
            copiedEventObject.allDay = allDay;

            // render the event on the calendar
            // the last `true` argument determines if the event `sticks`
            $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);

            // if the 'remove after drop' checkbox checked?
            if ($('#drop-remove').is(':checked')) {
                // if so remove the element from the "Draggable Events"
                $(this).remove();
            }
    },

but it's not doing what I wanted ...

但它没有做我想做的......

回答by MarCrazyness

Take a look at the Event Dragging and Resizing http://arshaw.com/fullcalendar/docs/event_ui/

看看事件拖动和调整大小http://arshaw.com/fullcalendar/docs/event_ui/

I think what you are looking for the eventDropcallback.

我认为您正在寻找eventDrop回调。

Triggered when dragging stops and the event has moved to a different day/time.

当拖动停止并且事件移动到不同的日期/时间时触发。

http://arshaw.com/fullcalendar/docs/event_ui/eventDrop/

http://arshaw.com/fullcalendar/docs/event_ui/eventDrop/

Example from arshaw's site:

来自 arshaw 网站的示例:

$('#calendar').fullCalendar({
    events: [
        // events here
    ],
    editable: true,
    eventDrop: function(event,dayDelta,minuteDelta,allDay,revertFunc) {

        alert(
            event.title + " was moved " +
            dayDelta + " days and " +
            minuteDelta + " minutes."
        );

        if (allDay) {
            alert("Event is now all-day");
        }else{
            alert("Event has a time-of-day");
        }

        if (!confirm("Are you sure about this change?")) {
            revertFunc();
        }

    }
});