我的最终目标是通过JSON动态传递eventSources。在甚至动态生成JSON内容之前,我试图使用文档示例通过JSON URL将一个简单的单个事件传递到我的事件代码中,该事件代码是手动编写的。
我可以看到该网址有效,因为我可以通过php在我的wordpress网站中回显结果,但是我将JSON网址传递给JS脚本时,日历就崩溃了。我真的很head头。
还提到了prev / next按钮触发带有本地时区日期的GET到JSON(例如,当前显示月份的范围)。我应该如何对json进行语法编码,以便让事件调用找到数据点范围?我对这一切真的很困惑。
JSON文件:calendar.json
{
"title" : "something",
"start" : "2019-04-23"
}
PHP文件:page-calendar.php
<?php
//Wordpress function for URL to the file location
$url = get_stylesheet_directory_uri() . '/calendar.json';
$data = file_get_contents($url);
$content = json_decode($data);
echo $content->title; // Just to test if the URL works
echo $content->start; // This echos just fine
?>
<html>
<head>
<meta charset='utf-8' />
<script>
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'dayGrid' ],
events: $url;
});
calendar.render();
});
</script>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
烙印99
蛊毒传说
蝴蝶不菲