您好,我尝试使用 EventSources 通过 sql 获取同一日历中的多个事件,但是当我尝试像 fullcalendar 文档那样操作时,日历会变成空白。我究竟做错了什么?这是我的 callendar 代码
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() { // DOMContentLoaded zorgt ervoor dat eerst de html laad
var calendarEl = document.getElementById('calendar'); // grab element reference
var calendar = new FullCalendar.Calendar(calendarEl, {
// Opties in fullcalendar
eventLimit: true,
locale: 'nl',
buttonText: {
month: 'Maand',
agendaDay: 'Dag',
agendaWeek: 'Week',
today: 'Vandaag',
listMonth: 'Lijst'
},
header: {
left: 'prev,next today',
center: 'title',
right: 'listMonth,month,agendaWeek,agendaDay'
},
eventSources: [
'/sql.php',
'/availability.php'
]
});
calendar.render();
});
</script>
最佳答案
您的 php 文件必须以 json 源的形式返回事件,
示例:
<?php
$event_array = array();
while ($row = $getCalenderItems->fetch()) {
$event_array[] = array(
"title" => $row['Docentnaam'] . ' ' . $row['Onderdeelnaam'] . ' ' . $row['Opleidingnaam'] . ' ' . $row['LocatiePlaats'],
"start" => new Date($row['Start']),
"end" => new Date($row['Eind'])
);
}
echo json_encode($event_array);
?>
调整您的 php 文件以将 json feed 返回到日历源,如上所示。
关于javascript - 带有 sql 的事件源在 Fullcalendar 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53651933/