我一般来说是 ajax/jquery 的新手,发现了 Adam Shaw 制作的 jquery 的 fullcalendar。这看起来正是我所需要的。
我找到了一些关于如何从 php/mysql 设置中读取它的教程,如果我使用他们告诉我的完全相同的字段名称(开始、结束等),这些教程就可以正常工作。我想知道如何告诉它使用我自己的日期字段作为开始和结束日期。我还想添加一些额外的字段,例如注释(我已经有一个日历数据库,其中包含我想使用的数据,而无需重组它,因为其他事物使用相同的数据库)。
字段名称示例:
- 开始日期
- 结束日期
- 评论
- 重复发生
如果有人能让我知道如何告诉它使用自定义日期字段以及显示其他自定义字段,那就太棒了。
我当前的脚本是: 目前使用的jquery/ajax
<script>
$(document).ready(function() {
var date = new Date();
var d = date.getDate(),
m = date.getMonth(),
y = date.getFullYear();
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
buttonText: {
today: 'Today',
month: 'Month',
week: 'Week',
day: 'Day'
},
events: "../calendar/internal/events.php"
});
});
</script>
事件.php
<?php
$json = array();
$requete = "SELECT * FROM internal_calendar ORDER BY id";
try {
$bdd = new PDO('mysql:host=localhost;dbname=calendarDB', 'root', 'securepassword');
} catch(Exception $e) {
exit('Unable to connect to database.');
}
$resultat = $bdd->query($requete) or die(print_r($bdd->errorInfo()));
echo json_encode($resultat->fetchAll(PDO::FETCH_ASSOC));
如有任何帮助,我们将不胜感激。
谢谢, jAC
最佳答案
在将结果设为 json 格式之前,您需要做一些事情以使 fullcalendar 作为事件可接受。
$result = $resultat->fetchAll(PDO::FETCH_ASSOC);
$events = array();
foreach ($result as $row) {
$events[] = array (
'start' => date('Y-m-d H:i:s', strtotime($row['startDate'])),
'end' => date('Y-m-d H:i:s', strtotime($row['endDate'])),
'comments' => $row['comments'],
'reoccuring' => $row['reoccuring'],
'title' => 'Set title here', // Set comment here to show in event block.
)
}
echo json_encode($events);
事件的标题属性用于在全日历中显示事件 block 中的数据。您可以将评论设置为标题。
'title' => $row['comments']
就是这样。
关于php - 如何在 jquery FullCalendar 中使用自定义字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35883220/