xxxxxxxxxx
1
<div id="calendar-11"></div>
1
1
xxxxxxxxxx
1
const events = [
2
{
3
summary: 'JS Conference',
4
start: {
5
date: Calendar.dayjs().format('DD/MM/YYYY'),
6
},
7
end: {
8
date: Calendar.dayjs().format('DD/MM/YYYY'),
9
},
10
color: {
11
background: '#cfe0fc',
12
foreground: '#0a47a9',
13
},
14
id: 1
15
},
16
{
17
summary: 'Vue Meetup',
18
start: {
19
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
20
},
21
end: {
22
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
23
},
24
color: {
25
background: '#ebcdfe',
26
foreground: '#6e02b1',
27
},
28
id: 2
29
},
30
{
31
summary: 'Angular Meetup',
32
description:
33
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur',
34
start: {
35
date: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY'),
36
dateTime: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY') + ' 10:00',
37
},
38
end: {
39
date: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY'),
40
dateTime: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY') + ' 14:00',
41
},
42
color: {
43
background: '#c7f5d9',
44
foreground: '#0b4121',
45
},
46
id: 3
47
},
48
{
49
summary: 'React Meetup',
50
start: {
51
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
52
},
53
end: {
54
date: Calendar.dayjs().add(8, 'day').format('DD/MM/YYYY'),
55
},
56
color: {
57
background: '#fdd8de',
58
foreground: '#790619',
59
},
60
id: 4
61
},
62
{
63
summary: 'Meeting',
64
start: {
65
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
66
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 8:00',
67
},
68
end: {
69
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
70
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 12:00',
71
},
72
color: {
73
background: '#cfe0fc',
74
foreground: '#0a47a9',
75
},
76
id: 5
77
},
78
{
79
summary: 'Call',
80
start: {
81
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
82
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 11:00',
83
},
84
end: {
85
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
86
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 14:00',
87
},
88
color: {
89
background: '#292929',
90
foreground: '#f5f5f5',
91
},
92
id: 6
93
}
94
];
95
96
const calendarElement = document.getElementById('calendar-11');
97
calendarElement.classList.add('calendar');
98
let newEventId = events.length;
99
100
const calendarInstance = new Calendar(calendarElement, {
101
newEventAttributes: (event) => {
102
newEventId++;
103
104
return {
105
...event,
106
id: newEventId
107
}
108
}
109
});
110
111
calendarInstance.addEvents(events);
112
113
document.getElementsByClassName('event').forEach((event) => {
114
event.addEventListener('click', (e) => {
115
const key = Number(event.dataset.mdbEventKey);
116
const index = calendarInstance.events.map(object => object.key).indexOf(key)
117
console.log(calendarInstance.events[index].id);
118
});
119
});
Console errors: 0