完整日历:检测调整大小是在“开始”还是“结束”



我正在使用FullCalendar库来构建时间表。我已经启用了editable属性,因此我可以调整事件的大小。我使用此事件侦听器来执行我想执行的操作:

eventResize: function(event,dayDelta,minuteDelta,allDay,revertFunc) {
                //Some code goes here
            }

但是我想知道是否有办法检测调整大小是在事件的开始日期还是在结束日期发生的?

好吧,我自己找到了解决方案。我们可以只保留eventResizeStarteventResizeStop事件期间的记录,然后比较这些记录。我的意思是这样的:

eventResizeStart: function(event) {     
    startDateOnStart = event.start;
    endDateOnStart = event.end;         
}

然后

eventResizeStop: function(event) {  
    // I added 1 sec delay because in my experience the event object needs some time to update.
    setTimeout(
        function(){
             startDateOnStop = event.start;
             endDateOnStop = event.end;
             //Now let's compare the dates.
             if (startDateOnStart != startDateOnStop){
                  alert ('The resize took place at Start!');
                  // Do some things here.
             } else if (endDateOnStart != endDateOnStop ){
                      alert ('The resize took place at End!');
             }
    }, 1000);                   
}

这段代码更有效:

eventResizeStart: function(event) {     
            startDateOnStart = event.start.format();
            endDateOnStart = event.end.format();         
        },
        eventResize: function( event, delta, revertFunc, jsEvent, ui, view ) {
             startDateOnStop = event.start.format();
             endDateOnStop = event.end.format();
             if (startDateOnStart != startDateOnStop){
                  alert ('The resize took place at Start!');
             } else if (endDateOnStart != endDateOnStop ){
                  alert ('The resize took place at End!');
             }
        }

相关内容

  • 没有找到相关文章

最新更新