Joe*_*hin 2 jquery droppable fullcalendar
我能够将外部事件拖放到日历中,开始时间的默认行为是事件被删除的位置.我想设置默认行为,也将事件的结束时间设置为开始时间后1小时.这似乎微不足道,但我似乎无法让它工作.下面是我的drop函数(基本上是droppable items demo加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();
}
},
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
谢谢,Joe Chin
您尝试执行此操作的示例中的问题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
....
Run Code Online (Sandbox Code Playgroud)
编辑:好的,我实际上尝试过这个版本. 它似乎工作.