FullCalendar:在 drop 函数中设置事件结束
我能够将外部事件拖放到日历中,默认行为的开始时间是事件被删除的时间。我想将默认行为设置为将事件的结束时间设置为开始时间后 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();
}
},
有什么想法吗?
谢谢, 陈乔恩
I have the ability to drag and drop external events to the calendar with the default behavior of start time being where the event was dropped. I would like to set the default behavior to also set the end time for the event to be 1 hour after the start time. This seems trivial but I can't seem to get it working. Below is my drop function (essentially the droppable items demo plus 1 line.)
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();
}
},
Any ideas?
Thanks,
Joe Chin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
该示例中您尝试执行的操作的问题是
allDay
设置为 true,因此它会忽略开始日期中指定的小时数。如果您愿意将时间设置为午夜 - 凌晨 1 点作为默认值,那么您可以执行以下操作:编辑:好的,我实际上尝试了这个版本。它似乎有效。
The problem in that example for what you're trying to do is that
allDay
is set to true, so it ignores the hours specified in the start date. If you were happy with say the time being midnight - 1am as the default, here's what you could do:EDIT: OK, I actually tried this version. It seems to work.
日历属性
http://arshaw.com/fullcalendar/docs/agenda/defaultEventMinutes/
设置从开始算起的默认结束时间
Calendar property
http://arshaw.com/fullcalendar/docs/agenda/defaultEventMinutes/
sets de default end time from start
我无法让 Ryley 发布的解决方案正常工作。它将外部事件放置在日历的标题处,当我查看一周时,该事件将是一条细线(它看起来折叠)或根本不出现。这可能是 fullCalendar 版本差异(我使用的是 fullCalendar v2)。在 fullCalendar 的 v2 中,我能够使其正常工作,而不会在任何日历视图中出现任何事件问题。
I couldn't get the solution posted by Ryley to work properly. It would place the external event at the header of the calendar and when I viewed the week, the event would be a thin line (it appeared collapsed) or not appear at all. This may be a fullCalendar version difference (I'm using v2 of fullCalendar). In v2 of fullCalendar I was able to get this to work without any problems of the event within any of the calendar views.
版本2以上,“eventReceive”-丢弃后调用的事件。
然后使用“event.setEnd(date);”更改结束日期。
文档 eventReceive:链接
文档 setEnd:链接
Above version 2, "eventReceive"-event called after dropped.
Then use "event.setEnd(date);" to change end date.
Documentation eventReceive: link
Documentation setEnd: link