我正在使用具有拖放功能的Angular的fullcalendar模块。 当用户在日历上放置新事件时,我想设置ID。但是我不知道该如何设置。
这是Stackblitz URL。 下面也是eventReceive函数。
eventReceive(event) {
const dataSet = event.draggedEl.dataset.event;
const dataJson = JSON.parse(dataSet);
const eventIndex: number = this.eventList.findIndex(d => d.id === dataJson.id);
this.eventList.splice(eventIndex, 1);
const isAllday = event.event.allDay;
const endEventDate = event.event.end;
const startEventDate = new Date(event.event.start);
const EventTimeObject: any = {
type: 'event',
id: dataJson.id,
start: startEventDate.toUTCString(),
title: dataJson.title,
color: dataJson.color
};
if (isAllday) {
const endTime = new Date(startEventDate);
const endTimeHour = endTime.setHours(23, 59, 59, 999);
EventTimeObject.end = endTimeHour;
}
if (!isAllday && endEventDate === null) {
const endTime = new Date(startEventDate);
const endTimeHour = endTime.setHours(endTime.getHours() + 1);
EventTimeObject.end = endTimeHour;
} else if (endEventDate) {
EventTimeObject.end = new Date(endEventDate).getTime();
}
this.eventsModel = [...this.eventsModel, EventTimeObject];
console.log(this.eventsModel);
// this.plannerService.addActionDates(EventTimeObject);
}
答案 0 :(得分:1)
好的,我已经弄清楚了,
但是我不确定这是否是正确的方法,
解决方案是需要在draggrable
对象中添加ID
draggableEvent() {
new Draggable(this.external.nativeElement, {
itemSelector: '.fc-event',
eventData(eventEl) {
return {
title: eventEl.innerText,
id: eventEl.id
};
}
});
}