gpt4 book ai didi

javascript - Fullcalendar drop外部事件恢复功能

转载 作者:行者123 更新时间:2023-12-01 04:37:34 30 4
gpt4 key购买 nike

我正在尝试使用 fullcalendar 库创建一个事件日历,并遵循演示external-dragging,我理解这个概念,只是想知道如何执行恢复函数如果我按取消,放置事件将返回到其原始位置。

我正在使用 sweetalert2 库替换默认的 javascript 警报,下面是我的代码。

$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month'
},
editable: true,
eventConstraint: {
start: moment().format('YYYY-MM-DD'),
end: '2100-01-01' // hard coded goodness unfortunately
},
droppable: true, // this allows things to be dropped onto the calendar
drop: function() {
// is the "remove after drop" checkbox checked?

if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the "Draggable Events" list
$(this).remove();

}

swal({
title: 'Are you sure?',
text: "You want to change this event schedule?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, proceed'
}).then(function (result) {
if (result.value) {


swal(
'Success!',
'The event schedule was successfully changed to ',
'success'
)



}else{

revertFunc();

}
})
//end of drop

},

revertFunc(); 仅在 eventDrop 上可用,但我不知道如何在 drop 事件上实现它,任何建议都是太棒了

最佳答案

“drop”回调中没有“revertFunc()”。它根本不存在。

我的解决方法(FullCalendar v4)是管理 EventLeaveEventReceive:在第一个中保存原始事件,在第二个中删除新事件并恢复原来的。

这是一个简化版本:

// to map original events (event.id => event)
_oldEventsInfo = new Map();

eventLeaveHandler(info) {
_oldEventsInfo.set(info.event.id, info);
}

eventReceiveHandler(info) {
if (/* for any reason cannot be moved */) {
this.revert(info);
} else {
_oldEventsInfo.delete(info.event.id);
}
}

revert(info) {
var oldInfo = _oldEventsInfo.get(info.event.id);
if (oldInfo) {
// build a new event to restore in the original calendar
var oldCalendar = oldInfo.event._calendar;
var restoredEvent = {
id: oldInfo.event.id,
// etc
};
oldCal.addEvent(restoredEvent);
// delete the destination (dragged) event from dest calendar
info.event._calendar.getEventById(info.event.id).remove();
// remove the old event from my saved
_oldEventsInfo.delete(info.event.id);
}
}

关于javascript - Fullcalendar drop外部事件恢复功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47407927/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com