gpt4 book ai didi

jquery - FullCalendar:在 drop 函数中设置事件结束

转载 作者:行者123 更新时间:2023-12-01 02:49:19 25 4
gpt4 key购买 nike

我能够将外部事件拖放到日历中,默认行为的开始时间是事件被删除的时间。我想将默认行为设置为将事件的结束时间设置为开始时间后 1 小时。这看起来微不足道,但我似乎无法让它发挥作用。下面是我的放置函数(本质上是可放置元素演示加上 1 行。)

drop: function(date, allDay) { // this function is called when something is dropped

// 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 to the same object
var copiedEventObject = $.extend({}, originalEventObject);

// assign it the date that was reported
copiedEventObject.start = date;
copiedEventObject.end = date.setHours(date.getHours()+1); // <- should be working
copiedEventObject.allDay = allDay;

// render the event on the calendar
// the last `true` argument determines if the event "sticks"
// (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
$('#calendar').fullCalendar('renderEvent', copiedEventObject, true);

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

有什么想法吗?

谢谢,陈乔恩

最佳答案

该示例中您尝试执行的操作的问题是 allDay 设置为 true,因此它会忽略开始日期中指定的小时数。如果您愿意将时间设为午夜 - 凌晨 1 点作为默认值,那么您可以执行以下操作:

var tempDate = new Date(date);  //clone date
copiedEventObject.start = date;
copiedEventObject.end = new Date(tempDate.setHours(tempDate.getHours()+1)); // <-- make sure we assigned a date object
copiedEventObject.allDay = false; //< -- only change
....

编辑:好的,我实际上尝试过这个版本。它似乎有效。

关于jquery - FullCalendar:在 drop 函数中设置事件结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4169570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com