我在 fullcalendar 版本 3 中很好地使用了资源。我正在迁移到版本 4 并进行了一些重大更改。我可以让日历正确显示我的事件,但是一旦我开始添加资源,我的控制台中就会出现此错误:
main.js:145 Uncaught TypeError: Cannot read property 'ResourceDayGrid' of undefined
代码:
document.addEventListener('DOMContentLoaded', function() {
var calendar_full = document.getElementById('calendar_full');
var calendar = new FullCalendar.Calendar(calendar_full, {
selectMirror: true,
plugins: ['interaction', 'resourceDayGrid', 'resourceTimeGrid'],
header: {
right: 'prevYear,prev,next,today,nextYear',
center: 'title',
left: 'resourceTimeGridDay,resourceTimeGridTwoDay,timeGridWeek,dayGridMonth'
},
views: {
resourceTimeGridTwoDay: {
type: 'resourceTimeGrid',
duration: {
days: 2
},
buttonText: '2 days',
}
},
defaultView: 'resourceTimeGridDay',
datesAboveResources: true,
editable: true,
slotDuration: "<?php echo $location->data()->calendar_slot_duration; ?>",
snapDuration: "<?php echo $location->data()->calendar_snap_duration; ?>",
nowIndicator: true,
minTime: "<?php echo $location->data()->calendar_start; ?>",
maxTime: "<?php echo $location->data()->calendar_end; ?>",
hiddenDays: $.parseJSON('[' + "<?php echo $location->data()->calendar_hide_days_of_week; ?>" + ']'),
// groupByResource: true,
eventLimit: true,
schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',
events: {
url: 'ajax_get_json.php?what=location_appointments'
},
resources: [{
id: '1',
title: 'Room A'
},
{
id: '2',
title: 'Room B'
}
]
});
calendar.render();
})
这是一个事件 JSON 响应示例:
allDay: false
color: "#FFD700"
company_id: "1"
date_created: "2018-12-05 09:35:32"
start: "2019-04-30 14:00:00"
end: "2019-04-30 14:00:00"
id: "22218"
resourceId: "1"
如果我将默认视图更改为不依赖资源的视图,则日历会显示所有事件。所以这将呈现日历:
defaultView: 'dayGridMonth'
当我使用使用资源的 defaultViews 时,我得到了错误。
不知道如何解决这个问题。
更新以添加以下脚本包括:
<link href="added-assets/plugins/fullcalendar-4.0.2/packages/core/main.css" rel="stylesheet" />
<link href="added-assets/plugins/fullcalendar-4.0.2/packages/daygrid/main.css" rel="stylesheet" />
<link href="added-assets/plugins/fullcalendar-4.0.2/packages/timegrid/main.css" rel="stylesheet" />
<script src="added-assets/plugins/fullcalendar-4.0.2/packages/core/main.js" type="text/javascript"></script>
<script src="added-assets/plugins/fullcalendar-4.0.2/packages/daygrid/main.js" type="text/javascript"></script>
<script src="added-assets/plugins/fullcalendar-4.0.2/packages/interaction/main.js" type="text/javascript"></script>
<script src="added-assets/plugins/fullcalendar-4.0.2/packages/timegrid/main.js" type="text/javascript"></script>
<script src="added-assets/plugins/fullcalendar-4.0.2/packages/resource-common/main.js" type="text/javascript"></script>
<script src="added-assets/plugins/fullcalendar-4.0.2/packages/resource-timegrid/main.js" type="text/javascript"></script>
<script src="added-assets/plugins/fullcalendar-4.0.2/packages/resource-daygrid/main.js" type="text/javascript"></script>
另外,如果有帮助:我将错误从控制台错误跟踪到以下行(ResourceDayGrid 函数有错误):
_this.resourceTimeGrid = new ResourceTimeGrid(context, _this.timeGrid);
if (_this.dayGrid) {
_this.resourceDayGrid = new resourceDaygrid.ResourceDayGrid(context, _this.dayGrid);
}