嗨我正在使用fullCalendar 1.5.1,並且我創建了一個PHP查詢,它返回幾乎所有我想在日曆中使用的東西。這是一個集成的系統,所以我不得不爲了切換到_ASSOC只返回庫MySQLi asssociative陣列:如何使用不帶URL的JSON編碼數組?
<?php
global $json_result;
global $myqueryresult;
$GLOBALS["ADODB_FETCH_MODE"] = ADODB_FETCH_ASSOC;
$myquery = "SELECT id, title, eventstart, eventend FROM View1";
$myqueryresult = $GLOBALS["conn"]->GetAll($myquery);
$json_result = json_encode($myqueryresult);
$GLOBALS["ADODB_FETCH_MODE"] = ADODB_FETCH_BOTH;
?>
...但它不會接受的數據,因爲在鍵/值對的關鍵是引用(按照JSON標準,所以我讀過)。
如果我只輸入生成的MySQL數組,那麼Javascript只會將數據顯示爲「Array」。如果我在數組上使用json_encode(),我會得到看起來是正確的JSON對象的東西,但由於引用了鍵,它不適用於fullCalendar。
這裏是我的jQuery的fullcalendar:
$(document).ready(function() {
$('#calendar').fullCalendar({
height: 600,
firstDay: 6,
theme: true,
year: 2012,
month: 0,
date: 7,
minTime: 6,
maxTime: 23,
startParam: 'eventstart',
endParam: 'eventend',
defaultView: 'agendaWeek',
allDaySlot: false,
slotMinutes: 15,
events: <?php echo $json_result; ?>
// put your options and callbacks here
})
});
這裏是生成的HTML源代碼,如果我使用$ json_result MySQL的數組:
$(document).ready(function() {
$('#calendar').fullCalendar({
<...snip...>
slotMinutes: 15,
events: Array
// put your options and callbacks here
})
});
這裏是結果,如果我使用json_encode ($ thesamearray)
$(document).ready(function() {
<...snip...>
events: [{"id":"51","title":"Ship in Miami, Florida","eventstart":"2012-01-07 07:00:00","eventend":"2012-01-07 15:00:00"},{"id":"547","title":"Miami, Florida","eventstart":"2012-01-14 07:00:00","eventend":null}]
// put your options and callbacks here
})
});
我該如何調整它,以便它可以作爲一個數組fullCalendar?它似乎不想採用JSON字符串或數組,至少現在使用PHP中的數組格式。
謝謝, 克里斯
SOLUTION:
別名MySQL的領域:
<?php
global $json_result;
$GLOBALS["ADODB_FETCH_MODE"] = ADODB_FETCH_ASSOC;
$myquery = "SELECT id, title, eventstart AS start, eventend AS end FROM View1";
$myqueryresult = $GLOBALS["conn"]->GetAll($myquery);
$json_result = json_encode($myqueryresult);
$GLOBALS["ADODB_FETCH_MODE"] = ADODB_FETCH_BOTH;
?>
還調整了jQuery來刪除我的啓動/ endparams,改變allDaySlot到allDayDefault:
$(document).ready(function() {
$('#calendar').fullCalendar({
height: 600,
firstDay: 6,
theme: true,
year: 2012,
month: 0,
date: 7,
minTime: 6,
maxTime: 23,
defaultView: 'agendaWeek',
allDayDefault: false,
slotMinutes: 15,
events: <?php echo $json_result; ?>
// put your options and callbacks here
})
});
現在,如果我只能找到一種方法讓它顯示8天的橫向議程,我的麻煩就可以結束了!感謝所有提示。
'json_encode'd數組看起來對我來說很好。對於FullCalendar而言,引用對象鍵不會有任何影響。 – 2011-06-05 01:06:36
你是對的,它確實需要引用鍵很好,謝謝你。 – Chris 2011-06-05 01:53:08