我嘗試將FullCalendar與我的Joomla組件集成。我寫在我的控制器JSON提要:FullCalendar與JSON的Joomla組件集成
public function getAvails()
{
$app = JFactory::getApplication();
$document = JFactory::getDocument();
$admin_id = $app->input->get('admin_id');
$place_id = $app->input->get('place_id');
$model = $this->getModel('Avails');
$model->setState('filter.admin_id', $admin_id);
$model->setState('filter.place_id', $place_id);
$items = $model->getItems();
$document->setMimeEncoding('application/json');
JResponse::setHeader('Content- Disposition','attachment;filename="result.json"');
echo json_encode($items);
exit;
}
導致JSON:
[
{
"id": "1",
"title": "Spotkanie z: 0 Miejsce: Bergen",
"start": "2015-06-10",
"end": "2015-06-10",
"color": ""
},
{
"id": "2",
"title": "Spotkanie z: 0 Miejsce: Oslo",
"start": "2015-06-17",
"end": "2015-06-17",
"color": "#17cce8"
},
{
"id": "3",
"title": "Spotkanie z: 0 Miejsce: Oslo",
"start": "2015-06-29",
"end": "2015-06-29",
"color": "#17cce8"
}
]
我的javascript代碼:
jQuery(document).ready(function() {
jQuery.ajax({
url: 'index.php?option=com_meetings&task=avails.getavails&format=json',
type: 'POST',
async: false,
success: function(response){
json_events = response;
}
});
// page is now ready, initialize the calendar...
alert(json_events);
jQuery('#calendar').fullCalendar({
events: json_events,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
}
})
});
});
而且它並不在FullCalendar給出任何結果。但是,如果我將我的json結果直接分配給事件,而不是在fullCalendar函數中的json_events變量,它就可以工作!
我在做什麼錯?
我的JSON有問題嗎?
確認無誤。