我希望能够拖动外部元素并将它们放在我的完整日历上。在drop回调中,我请求一个页面,该页面返回事件原因类型的计算返回时间(例如:"2012-03-03 08:00:00")。接收日期并将其应用于事件的.end属性。事件被添加到日历中,但事件默认为2小时,导致事件的结束时间错误(应延长到下一个"08:00")。如果我切换到周视图,将显示正确的结束时间,如果我切换回周视图,也会显示正确的终止时间。此外,如果我将具有错误播放结束时间的事件拖到日历上的新位置,它将以正确的结束时间("08:00")重新播放。
那么,有人知道如何模拟dragEventStop或它正确重新发送所需的任何东西吗?
代码:
drop: function(date, allDay) { // this function is called when something is dropped
// retrieve the dropped element's stored Event Object
var originalEventObject = jQuery(this).data('eventObject');
// we need to copy it, so that multiple events don't have a reference to the same object
var copiedEventObject = jQuery.extend({}, originalEventObject);
// assign it the date that was reported
copiedEventObject.start = date;
//Fetch endtime from loadReturntime
var opt = {session: '<%= GetVariable('session') %>', cmd: 'hv_get_returntime', reasoncode_id: ''+jQuery(this).attr('custom:reasoncode')+'', fromtime: ISODateString(date)};
jQuery.get('engine.wsc', opt, function(data) {
copiedEventObject.end = new Date(data);
});
copiedEventObject.allDay = false;
// render the event on the calendar
jQuery('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
},
我发现答案是jQuery.get()的回调是在(当然)函数的剩余行之后处理的。因此,在处理回调并将结束日期设置为正确日期之前,将呈现事件。解决方案是在get()的回调中添加渲染。例如:
drop: function(date, allDay) { // this function is called when something is dropped
// retrieve the dropped element's stored Event Object
var originalEventObject = jQuery(this).data('eventObject');
// we need to copy it, so that multiple events don't have a reference to the same object
var copiedEventObject = jQuery.extend({}, originalEventObject);
var opt = {session: '<%= GetVariable('session') %>', cmd: 'hv_get_returntime', reasoncode_id: ''+jQuery(this).attr('custom:reasoncode')+'', fromtime: ISODateString(date)};
jQuery.get('engine.wsc', opt, function(data) {
copiedEventObject.end = new Date(data);
// assign it the date that was reported
copiedEventObject.start = date;
copiedEventObject.allDay = allDay;
// render the event on the calendar
jQuery('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
});
},