问题描述
我正在开发一个项目symfony3,将googleCalendar与fullcaldendar整合在一起。我想使用googlecalendar来提供fullcalendar以显示我在googlecalendar中的所有事件,然后每当我在fullcalendar中更改事件时,它也会在googlecalendar中更改。所以步骤是从googleCalendar获取google事件,我已经完成了,并且试图将其格式化为json:
i am working on a project symfony3 to integrate googleCalendar with fullcaldendar. I'd like to use the googlecalendar to feed the fullcalendar to show all the events i had in googlecalendar,and then each time when i change a event in fullcalendar, it will be changed also in googlecalendar. So the step is to get the google events from googleCalendar which i have done already and i have tried to make it in format of json:
$ myjsonfile:
$myjsonfile:
[{
"title": "Rdv Ecole",
"start": "2017-11-13T10:00:00+01:00",
"end": "2017-11-13T12:00:00+01:00"
}, {
"title": "testing functions",
"start": "2017-11-20T13:15:00+01:00",
"end": "2017-11-20T14:15:00+01:00"
}, {
"title": "another test",
"start": "2017-11-20T17:30:00+01:00",
"end": "2017-11-20T18:30:00+01:00"
}, {
"title": "reuinion data vc",
"start": "2017-11-21T09:00:00+01:00",
"end": "2017-11-21T10:00:00+01:00"
}]
因为我使用的是symfony3,所以我做了一个
Because i am using symfony3, so i make a
return $this->render('calendar/loadcalendar.html.twig',['gevents'=>$myjsonfile]);
然后在我的页面上显示事件:
And then in my page to show the event:
$(document).ready(function() {
$('#calendar').fullCalendar({
defaultView: 'agendaWeek',
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
navLinks: true, // can click day/week names to navigate views
selectable: true,
selectHelper: true,
select: function(start, end) {
var title = prompt('Event Title:');
var eventData;
if (title) {
eventData = {
title: title,
start: start,
end: end
};
$('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
}
$('#calendar').fullCalendar('unselect');
},
eventLimit: true, // allow "more" link when too many events
eventSources: [
{
url: "http://localhost/prog/web/app_dev.php/calendar/load",
dataType: "json",
method: 'GET'
}
],
eventClick: function(event) {
var title = prompt('Change Event title:');
event.title = title;
$('#calendar').fullCalendar('updateEvent', event);
}
});
现在问题是我无法从我发送的json加载事件,所以可以有人给我一些建议?谢谢
Now the problem is that i can't load the events from the json i have send,so can someone give me some advices? thanks
推荐答案
在我的项目中,我这样做:
In my project, I do it this way:
$('#calendar').fullCalendar({
/* [...] */
events: "{{ path('ajax_calendar_load') }}",
/* [...] */
常规json:
And my load action return regular json:
$response = new JsonResponse();
$response->setContent($events);
return $response;
这篇关于整合谷歌日历与fullcalendar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!