我在使用Weekly事件日历Weekly event calender
时遇到问题在这个演示中,为事件传递了静态数组,代码为:
function getEventData() {
var year = new Date().getFullYear();
var month = new Date().getMonth();
var day = new Date().getDate();
return {
events : [
{
"id":1,
"start": new Date(year, month, day, 12),
"end": new Date(year, month, day, 13, 30),
"title":"Lunch with Mike"
},
{
"id":2,
"start": new Date(year, month, day, 14),
"end": new Date(year, month, day, 14, 45),
"title":"Dev Meeting"
},
{
"id":3,
"start": new Date(year, month, day + 1, 17),
"end": new Date(year, month, day + 1, 17, 45),
"title":"Hair cut"
},
{
"id":4,
"start": new Date(year, month, day - 1, 8),
"end": new Date(year, month, day - 1, 9, 30),
"title":"Team breakfast"
},
]
};
}
我希望这些数据来自使用PHP的mysql。为此,我写了PHP代码
$query="Select id, start_time, end_time, title from calendar_events where status=1";
$result=mysql_query($query);
$count=mysql_num_rows($result);
$i=1;
while($row=mysql_fetch_array($result)) {
$myarray[] = array("id"=>$i,"start"=>$row['start_time'], "end"=>$row['end_time'], "title"=>$row['title']);
$i++;
}
我在Javascript中获取此数组:
<script>
var myarr = <?php echo json_encode($myarray); ?>;
</script>
现在我想在日历中使用这些数据。我尝试了很多方法,但无法取得成功。 请帮助。
答案 0 :(得分:0)
如果我理解你的问题,试试这个:
<script>
function getEventData() {
return json_encode('events'=>$myarray);
}
</script>