简体   繁体   English

使用fullCalendar将allDay设置为false时,如何动态设置事件的开始和结束时间?

[英]How to set event start and end time dynamically when allDay is set to false with fullCalendar?

I am using a fullcalendar application where upon clicking on an event it opens a modal with event information. 我正在使用全日历应用程序,在其中单击事件时,它将打开一个包含事件信息的模式。 In this modal, it is possible to change event data too, think of event.start, event.end, and event.allDay. 在这种模式下,也可以更改事件数据,考虑一下event.start,event.end和event.allDay。

When the allDay checkbox is clicked, the event is automatically updated to represent the new state, however, when the event has been a non-allDay event before. 单击allDay复选框后,该事件将自动更新以表示新状态,但是,如果该事件以前是nonallall事件。 The event data contains two extra properties: oldStart and oldEnd. 事件数据包含两个额外的属性:oldStart和oldEnd。 These two properties I want to be used when the event.allDay is set to false; 当event.allDay设置为false时,我想使用这两个属性。 the event.start should then be set to oldStart and event.end should be set to oldEnd. 然后应将event.start设置为oldStart,并将event.end设置为oldEnd。

The problem is that with this method, when updating the start and end time of an event after setting event.allDay to false, the event when updated disappears from the calendar view and is being updated in the back-end to represent the start time as 00:00 and end time as the event start + defaultEventDuration (which in my case is 02:00:00). 问题在于,使用此方法时,在将event.allDay设置为false后更新事件的开始和结束时间时,更新后的事件将从日历视图中消失,并在后端进行更新以将开始时间表示为00:00和结束时间作为事件开始时间+ defaultEventDuration(在我的情况下为02:00:00)。

My code looks like this: 我的代码如下所示:

function changeAllDay(id) { // Function to change allDay property of event that was clicked on

    // Find corresponding event
    var event = findEvent(id);

    event.allDay = !event.allDay; // Change allDay value

    // Set start and end time to midnight if event is allDay
    if (event.allDay) {

        event.oldStart = event.start;
        event.oldEnd = event.end;

        event.start.set('hours', 00);
        event.start.set('minutes', 00);
        event.end.set('hours', 00);
        event.end.set('minutes', 00);

    } else {

        event.start = event.oldStart;
        event.end = event.oldEnd;
    };

    updateEvent(event);
}

The updateEvent() function does an API call to update the event in the back-end, and when succesful the event is updated with updateEvent()函数执行API调用以更新后端中的事件,并在成功后将事件更新为

$('#calendar').fullCalendar('updateEvent', event);

Can anybody tell me what I am missing here? 有人可以告诉我我在这里想念什么吗?

Make a copy of your dates when stashing them. 存放日期时,请复制日期。 You are calling set right after, and that wipes out your original times. 您之后马上打电话给set ,这消磨了您的原始时间。

    event.oldStart = event.start.clone();
    event.oldEnd = event.end.clone();

When you switch back from allDay, your events have no duration. 当您从allDay切换回时,您的活动将没有持续时间。

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

相关问题 时间不全时无法调整事件的大小Day fullcalendar - Unable to resize event when time is not allDay fullcalendar 当allDay为true时,fullcalendar返回事件结束null - fullcalendar return event end null when allDay is true 如何在angularjs的fullcalendar中动态设置许多事件? - How to set dynamically many event in fullcalendar in angularjs? FullCalendar JQuery插件设置calEvent.allDay = false,在议程视图中移动事件使它们消失 - FullCalendar JQuery plugin set calEvent.allDay = false, in agendaView moving events make them disappear 如何在事件 object 中为谷歌日历 api 设置开始和结束时间 - How to set start and end time in event object for google calendar api 尽管指定了时间且allDay为false,但React FullCalendar不显示时间 - React FullCalendar does not show the time although time is specified and allDay is false 在FullCalendar中为allDay事件的开始和结束时刻禁用UTC - Disable UTC for allDay events' start and end moment in FullCalendar 反应 FullCalendar 不显示 allDay 事件 - React FullCalendar not showing allDay event 如何在 fullcalendar 上获取开始和结束时间? - How can get start and end time on fullcalendar? 如何从FullCalendar中的事件获取弹出消息中事件的开始和结束时间? - How to get start and end time of event in popover message from an event in FullCalendar?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM