我正在使用 FullCalendar 在我的应用程序中实例化日历,即使我可以在我的网页上看到日历,我也无法执行 fullCalendar() 函数。它给了我一个 TypeError 说 jquery.js:4050 jQuery.Deferred exception: calendarEl.fullCalendar is not a function TypeError: calendarEl.fullCalendar is not a function
代码如下:
'use strict';
import { Calendar } from '@fullcalendar/core';
import dayGridPlugin from '@fullcalendar/daygrid'
import timeGridPlugin from '@fullcalendar/timegrid';
import 'fullcalendar';
export default class CalendarDisplay {
constructor() {
this.name = 'CalendarDisplay';
console.log('CalendarDisplay');
var calendarEl = document.getElementById('calendar');
let calendar = new Calendar(calendarEl, {
plugins: [dayGridPlugin,timeGridPlugin],
initialView: "timeGridWeek",
headerToolbar : {
left: 'prev,next',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
allDaySlot: false,
slotEventOverlap: false,
scrollTime: '08:00:00',
events: [
{
title: 'All Day Event',
start: '2021-05-24',
},
{
title: 'Long Event',
start: '2021-05-24T09:00:00',
end: '2021-05-24T24:00:00'
}
]
});
calendar.render();
calendarEl.fullCalendar({
viewRender: function(view, element) {
console.log("The view's title is " + view.intervalStart.format());
console.log("The view's title is " + view.name);
}
});
}
}
答案 0 :(得分:1)
您似乎混淆了现代 fullCalendar 和基于 jQuery 的旧版本的语法。 .fullCalendar()
是在 v3 及更低版本中运行方法的方式。使用 v5,如果你想调用一个方法,你可以直接调用。
但我认为无论如何在渲染日历之后您都不需要这个单独的调用。您似乎正在尝试设置视图更改时发生的情况。这可以在您的初始选项中设置,无需单独调用。
另一个问题是 viewRender
在 v5 中不再存在。它已被标准化的 view render hooks 取代。
所以实际上你可以通过这种方式实现你的目标:
'use strict';
import { Calendar } from '@fullcalendar/core';
import dayGridPlugin from '@fullcalendar/daygrid'
import timeGridPlugin from '@fullcalendar/timegrid';
import 'fullcalendar';
export default class CalendarDisplay {
constructor() {
this.name = 'CalendarDisplay';
console.log('CalendarDisplay');
var calendarEl = document.getElementById('calendar');
let calendar = new Calendar(calendarEl, {
plugins: [dayGridPlugin,timeGridPlugin],
initialView: "timeGridWeek",
headerToolbar : {
left: 'prev,next',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
allDaySlot: false,
slotEventOverlap: false,
scrollTime: '08:00:00',
events: [
{
title: 'All Day Event',
start: '2021-05-24',
},
{
title: 'Long Event',
start: '2021-05-24T09:00:00',
end: '2021-05-24T24:00:00'
}
]
viewDidMount: function(view, el) //view render hook for didMount
{
console.log("The view's title is " + view.currentStart.toISOString());
console.log("The view's title is " + view.title);
}
});
calendar.render();
calendarEl.fullCalendar({
viewRender: function(view, element) {
}
});
}
}