问题
I've read the entire documentation on Full Calendar and still I cannot render anything from a JSON source. I'm running Rails 3.2 and when I preview my JSON source with Google's Developer Tools I see the correctly formatted JSON objects and a Header with a Status Code of 200 and an Accept: application/json. I'm calling Full Calendar like so:
$('#calendar').fullCalendar({events: '/events'});
If I declare a single JSON object and then render it by itself it renders fine like so:
var event = {
"title": "Event 1",
"start": "1363794900",
"end": "1363794900",
"url": "/events/4"
}
$('#calendar').fullCalendar( 'renderEvent', event);
EDIT 1 In the events controller, index.json.erb looks like this:
<% @events.each do |event| %>
{
"title": "<%= event.name %>",
"start": "<%= event.from.strftime("%s") %>",
"end": "<%= event.to.strftime("%s") %>",
"url": "<%= event_path(event) %>"
}
<% end %>
and it's returning the following:
{
"title": "Matts Party",
"start": "1363794900",
"end": "1363794900",
"url": "/events/4"
}
{
"title": "Mateuszs Party",
"start": "1363795440",
"end": "1363795440",
"url": "/events/5"
}
{
"title": "Johns Party",
"start": "1363799400",
"end": "1363799400",
"url": "/events/6"
}
{
"title": "Mikes Party",
"start": "1364054040",
"end": "1364054040",
"url": "/events/3"
}
回答1:
The JSON code that your script generate is not correct. You can try to validate it here: http://jsonlint.com/ Paste your generated JSON code to see the issues.
Your structure is like this: {...}{...}{...}
Should be modified to this: [{...},{...},{...}]
来源:https://stackoverflow.com/questions/15582238/full-calendar-is-not-showing-events-from-json-source