我已阅读完整日历上的整个文档,但仍然无法从 JSON 源呈现任何内容。我正在运行 Rails 3.2,当我使用 Google 的开发人员工具预览我的 JSON 源代码时,我看到了格式正确的 JSON 对象和一个状态码为 200 的标头和一个 Accept: application/json。我这样称呼完整日历:
$('#calendar').fullCalendar({events: '/events'});
如果我声明一个 JSON 对象,然后自己渲染它,它会像这样渲染:
var event = {
"title": "Event 1",
"start": "1363794900",
"end": "1363794900",
"url": "/events/4"
}
$('#calendar').fullCalendar( 'renderEvent', event);
编辑 1 在事件控制器中,index.json.erb 如下所示:
<% @events.each do |event| %>
{
"title": "<%= event.name %>",
"start": "<%= event.from.strftime("%s") %>",
"end": "<%= event.to.strftime("%s") %>",
"url": "<%= event_path(event) %>"
}
<% end %>
它返回以下内容:
{
"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"
}