Why fullCalendar doesn't show event?
I try to show some events from database in my fullCalendar but it doesn't work? My app is on Symfony 3. First I installed the ancarebeca/fullcalendar, I followed the installation step by step and my agenda is here! In my controller, I have a method to return a JSON array like this:
[{"1":{"id":1,"title":"test","start":"2017-08-01 18:00:00","end":"2017-08-01 20:00:00","allDay":true,"editable":true,"startEditable":true,"durationEditable":true,"overlap":true,"url":"","backgroundColor":"","textColor":"","className":"","rendering":"","constraint":1,"source":"","color":""},"2":{"id":2,"title":"test2","start":"2017-08-02 15:00:00","end":"2017-08-02 16:00:00","allDay":true,"editable":true,"startEditable":true,"durationEditable":true,"overlap":true,"url":"","backgroundColor":"","textColor":"","className":"","rendering":"","constraint":1,"source":"","color":""}}]
If you want look my method:
public function loadAction()
{
//dump($calendarService);die();
$em = $this->getDoctrine()->getManager();
$evenements = $em->getRepository('MALrmBundle:CalendarEvent')->findAll();
$calendarService = $this->get('ma_lrm_bundle.service.listener');
$events = array();
foreach ($evenements as $key => $evenement)
{
$events[$evenement->getId()]=$calendarService->loadData($evenement);
}
$response = new JsonResponse($events);
return $response->setData(array($events));
}
At the end, in my js file, i just call the url, like this:
events: 'http://localhost/ligne_rh/web/app_dev.php/admin/accueil/calendar',
...But i have no return in my calendar...
i also post my full Js file:
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev, next',
center: 'title',
right: 'month, agendaWeek, agendaDay'
},
timezone: ('Europe/London'),
businessHours: {
start: '09:00',
end: '17:30',
dow: [1, 2, 3, 4, 5]
},
allDaySlot: false,
defaultView: 'agendaWeek',
lazyFetching: true,
firstDay: 1,
selectable: true,
timeFormat: {
agenda: 'h:mmt',
'': 'h:mmt'
},
/*columnFormat: {
month: 'ddd',
week: 'ddd D/M',
day: 'dddd'
},*/
editable: true,
eventDurationEditable: true,
events: 'http://localhost/ligne_rh/web/app_dev.php/admin/accueil/calendar',
});
});
Please help me.
Your JSON is structured differently than it expects.
[{"1":{"title":"test","start":"2017-08-01 18:00"}}]
should be like
[{"title":"Title","test":"2017-08-01 18:00"}]
To fix, try changing
$events[$evenement->getId()]=$calendarService->loadData($evenement);
to
$events[]=$calendarService->loadData($evenement);
As an aside, I'm not familiar with Symphony but the return may be as easy as return $response; since you already use $events in the $response = new JsonResponse($events);
or just return new JsonResponse($events);
链接地址: http://www.djcxy.com/p/39424.html