我正在使用FullCalendar库来构建时间表。我已经启用了editable
属性,因此我可以调整事件的大小。我使用此事件侦听器来执行我想执行的操作:
eventResize: function(event,dayDelta,minuteDelta,allDay,revertFunc) {
//Some code goes here
}
但是我想知道是否有办法检测调整大小是在事件的开始日期还是在结束日期发生的?
好吧,我自己找到了解决方案。我们可以只保留eventResizeStart
和eventResizeStop
事件期间的记录,然后比较这些记录。我的意思是这样的:
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!');
}
}