提问人:Kza 提问时间:10/24/2023 最后编辑:ADysonKza 更新时间:10/31/2023 访问量:33
fullCalendar 可拖动副本(angular)
fullCalendar draggable duplicates (angular)
问:
我使用 fullCalendar 创建了一个日历,可以在其中将一个或多个可拖动事件拖到我的日历中。
现在,当我添加一个事件并在日历中移动它时,它会被复制。
我不希望在日历中移动事件时事件数量增加。
private initializeCalendar() {
const calendarOptions: CalendarOptions = {
timeZone: 'UTC',
plugins: [resourceTimeGridPlugin, resourceTimelinePlugin, interactionPlugin],
initialView: 'resourceTimeGridFiveDay',
eventResizableFromStart: true,
droppable: true,
editable: true,
eventContent: this.renderEventContent,
eventClick: this.handleEventClick.bind(this),
drop: (info: any) => {
console.log("Drop function called");
// Check if the event is external
if (info.draggedEl && info.draggedEl.external) {
const title = info.draggedEl.innerText;
const start = info.date;
// Calculate the end time by adding the defaultEventDurationMinutes
const end = new Date(start);
end.setMinutes(start.getMinutes() + this.defaultEventDurationMinutes);
// Check if the event already exists
const existingEvent = this.calendarInstance?.getEvents().find(e =>
e.title === title &&
+e.start! == +start &&
e.extendedProps['resourceId'] === info.resource?.id // Use index signature here
);
// Add the event to the calendar if it doesn't already exist
if (!existingEvent) {
const eventData = {
title,
start,
end,
resourceId: info.resource?.id,
extendedProps: {
eventResizableFromStart: true,
external: true // Indicate that this event is external
},
};
if (this.calendarInstance) {
this.calendarInstance.addEvent(eventData);
}
// Optionally, remove the external event from the list
info.draggedEl.parentNode?.removeChild(info.draggedEl);
info.event.setExtendedProp('external', false);
}
}
},
// Initialize and render the calendar
this.calendarInstance = new Calendar(this.calendarElement.nativeElement, calendarOptions);
this.calendarInstance.render();
this.updateDayButtonText();
}
答: 暂无答案
评论