在拖动到新位置之前,fullcalendar中删除的外部元素的结束时间不适用

时间:2012-03-02 08:01:11

标签: javascript jquery calendar fullcalendar

我希望能够拖动外部元素并将其放在我的fullcalendar上。在drop回调中,我请求一个页面返回事件原因类型的计算返回时间(例如:“2012-03-03 08:00:00”)。收到日期并将其应用于事件的.end属性。并且事件被添加到日历中但事件默认为2小时长度导致事件具有错误的结束时间(应该延伸到下一个“08:00”)。如果我切换到周视图,则显示正确的结束时间,如果我切换回来。此外,如果我将具有错误的siplayed endtime的事件拖到日历上的新位置,则会使用正确的结束时间(“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);                                           
        },

1 个答案:

答案 0 :(得分:0)

我发现答案是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);                                                             
   });                              
},