在我看过的文档中,要添加他们使用的多个事件:
$('#calendar').fullCalendar({
events: [
{
title : 'event1',
start : '2010-01-01'
},
{
title : 'event2',
start : '2010-01-05',
end : '2010-01-07'
},
{
title : 'event3',
start : '2010-01-09 12:30:00',
allDay : false // will make the time show
}
]
});
但我无法在此处插入多个事件,其中事件日期将由db提供。因此,多个事件需要一个循环。有人可以帮我这个吗?
答案 0 :(得分:0)
我假设您使用的是PHP。上次我使用完整的日历时,我正在使用JSON获取并使用PHP构建了一组数据。
我有一个名为get_events.php
的php文件$result = mysql_query($query);
$jsonArray = array();
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$start = $row['heuredebut'];
$end = $row['heurefin'];
// Stores each database record to an array
$buildjson = array(
'id' => $row['id'],
'uid' => $row['uid'],
'title' => $row['title'],
'start' => "$start",
'end' => "$end",
'allDay' => false
);
// Adds each array into the container array
array_push($jsonArray, $buildjson);
}
// Output the json formatted data so that the jQuery call can read it
echo json_encode($jsonArray);
JQuery:
$('#calendar').fullCalendar({
events:'get_events.php'
});