javascript - Fullcalendar 4,使用 eventRender 时出现错误解析 JSON 失败
问题描述
我正在使用 FullCalendar 4,并且在脚本中设置了日历对象
function createBookingCalendar() {
var calendarEl = document.getElementById('bookingCalendar');
let calendar = new FullCalendar.Calendar(calendarEl, {
locale: 'en-gb', // the initial locale
timeZone: 'Europe/London',
plugins: ['interaction', 'list', 'timeGrid'],
header: {
left: 'prev,next today',
center: 'title',
right: 'listDay,listWeek,timeGridDay,timeGridWeek, dayGridWeek,DayGridMonth'
},
businessHours: [ // specify an array instead
{
daysOfWeek: [1, 2, 3, 4, 5], // Monday - Friday
startTime: '09:00', // 9am
endTime: '18:00' // 6pm
}, {
daysOfWeek: [6], // Saturday
startTime: '10:00', // 10am
endTime: '16:00' // 4pm
}
],
hiddenDays: [7],
// customize the button names,
// otherwise they'd all just say "list"
views: {
listDay: {
buttonText: 'Goto Day View'
},
listWeek: {
buttonText: 'Goto Week View'
},
timeGridDay: {
buttonText: 'Goto Time Grid Day View'
},
timeGridWeek: {
buttonText: 'Goto Time Grid Week View'
}
},
slotDuration: '02:00', // 2 hours
defaultView: 'listWeek',
defaultDate: Date.now(),
navLinks: true, // can click day/week names to navigate views
editable: false,
eventLimit: true, // allow "more" link when too many events
eventSources: [
// CAD Solutions Event Source (Remote Database)
{
url: '../php/getBookings.php',
method: 'GET',
failure: function () {
$.confirm({
theme: 'Modern',
icon: 'fas fa-exclamation-triangle',
title: 'Error',
content: '<p>There was an error fetching the bookings from our database, we appologise for the inconvenience.</p><p class="text-muted">This error has been logged with our engineers.</p><small>Error 0x86451 (Fetch Bookings Database Error)</small>',
type: 'red',
columnClass: 'col-md-6 col-md-offset-3',
buttons: {
close: {
text: 'Close.',
action: function () {
//reset flag and recall the function.
}
}
}
});
}
}
],
eventRender: function (info) {
var tooltip = new Tooltip(info.el, {
title: info.event.title,
content: 'asdadasdqweqweqweqweqwasssd',
placement: 'top',
trigger: 'hover',
container: 'body'
});
},
noEventsMessage: '<div class="panel panel-primary" style="height: 245px;width: 654px;margin:0 auto;padding:10px;margin-top:30px;"><div class="panel-heading"><h4><i class="fas fa-info-circle"></i> There are no bookings for this day.</h4></div><div class="panel-body"><p>There are no bookings saved for this date, you can add a booking to this day using the buttons below, or select a different date.</p><p class="text-muted">You can create a booking for this date as all timeslots are available.</small></div><div class="panel-footer"><a class="btn btn-primary" href="javascript:void(0);" id="addBooking" style="color:#fff;"><i class="fas fa-calendar-plus"></i> Create Booking For This Date.</a></div></div><div class="divider"> </div><div class="divider"> </div><div class="divider"> </div>',
eventClick: function (info) {
//Prevent Default Behaviour.
info.jsEvent.preventDefault();
$.confirm({
theme: 'Modern',
icon: 'fas fa-info-circle',
title: 'Selected Booking Information',
content: '<ul class="list-group list-group-flush" id="assetContent"><li class="list-group-item">Booking Company Name: ' + info.event.extendedProps.companyName + '</li><li class="list-group-item">Booking Date: ' + info.event.start + '</li><li class="list-group-item">Booking Slot: ' + info.event.startTime + ' - ' + info.event.endTime + '</li></ul>',
type: 'blue',
columnClass: 'col-md-6 col-md-offset-3',
buttons: {
close: {
text: 'Close.',
action: function () {
//reset flag and recall the function.
}
}
}
});
}
});
calendar.render();
}
当我在代码中设置了eventRender时,日历会停止从我的源中获取事件,并显示我在函数中添加的eventSources>failure对话框。
当我删除脚本的 eventRender 部分时,日历对象会完美呈现,并且我能够从我的数据库中查看所有事件。
有人能指出我的编码哪里出错了吗?真的很想让 eventRender 部分工作,这样我就可以更改设置的事件的背景颜色,此外,在源从服务器获取事件后,我将如何添加我自己的事件?我想这样做,以便我可以填写日历中缺少的时间段,以便用户可以选择一个空闲时间段来创建预订。
非常感谢
编辑我取出了我在完整日历文档中找到的工具提示代码,并将其替换为 ui 工具提示,现在可以使用了。添加我自己的事件的程序是什么?
解决方案
推荐阅读
- javascript - 如何使用 Selenium Java 框架自动化 Shadow DOM
- c++ - 我们什么时候应该编写自己的移动构造函数(移动赋值运算符)
- arrays - 有没有办法在 C 语言的表格形式输出期间处理空格?
- pytorch - sqrt_vml_cpu 未针对“长”实现
- python - 在Python中引用子目录之间文件的正确方法和VSCode设置是什么
- postgresql - 如何使用 date_part 函数将每月的值拆分为每天和国家
- javascript - 是否有可用于 node.js 的 array_walk_recursive php 函数的替代方法?
- android - 根据构建风格从清单中删除权限
- grails - 圣杯4升级
- python - 聚合和分组,Key Error on Size