解决
这是我的整个回复:
{
"data": [
{
"id": 3,
"calendar_id": 1,
"title": "asdasd",
"start": "2017-06-20 14:06:00",
"end": "2017-06-20 16:06:00",
"allDay": 0,
"className": "bg-green",
"deleted_at": null
}
]
}
定义:
$('#calendar').fullCalendar({
slotDuration: //..
minTime: //...
maxTime: //..
defaultView: //...
defaultDate: //..
header: {
//...
},
eventSources: [
{
url: '/api/calendar_events/' + id,
type: 'GET',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
error: function () {
alert('there was an error while fetching events!');
}
}
],
eventLimit: //..
selectable: //..
});
EventSources有什么问题?将呈现fullcalendar,但不会显示任何事件。
注意:我想使用eventSources而不是事件,因为可能有多个来源。
答案 0 :(得分:1)
这样做了:
eventSources: [
{
events: function (start, end, timezone, callback) {
$.ajax({
url: '/api/calendar_events/' + id,
type: 'GET',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}, success: function (response) {
var events = [];
$(response['data']).each(function () {
events.push({
id: $(this).attr('id'),
title: $(this).attr('title'),
start: $(this).attr('start'),
end: $(this).attr('end'),
className: $(this).attr('className'),
allDay : $(this).attr('allDay'),
});
});
callback(events);
}
});
}
}
],