问题描述
我已阅读完整日历上的整个文档,但仍无法从JSON源渲染任何内容。我正在运行Rails 3.2,当我使用Google的开发人员工具预览我的JSON源代码时,我看到格式正确的JSON对象以及状态代码为200和Accept:application / json的Header。我打电话给全日历如下:
$('#calendar')。fullCalendar({events:'/ events' });
如果我声明一个单独的JSON对象,然后单独渲染它, p>
var event = {
title:Event 1,
start:1363794900 ,
end:1363794900,
url:/ events / 4
}
$('#calendar')。fullCalendar 'renderEvent',event);
编辑1
在事件控制器中,index.json .erb看起来像这样:
<%@ events.each do | event | %GT;
{
title:<%= event.name%>,
start:<%= event.from.strftime(%s) %>,
end:<%= event.to.strftime(%s)%>,
url:<%= event_path(event )%>
}
<%end%>
并返回以下内容:
<$ p
title:Matts Party,
start:1363794900,
end:1363794900,
url:/ events / 4
}
{
title:Mateuszs Party,
start:1363795440,
end:1363795440,
url:/ events / 5
}
{
title:约翰党,
开始:1363799400,
end:1363799400,
url:/ events / 6
}
{
title :Mikes Party,
start:1364054040,
end:1364054040,
url:/ events / 3
}
脚本生成的JSON代码不正确。
您可以尝试在此处验证它:
粘贴您生成的JSON代码以查看问题。
您的结构如下所示:
{...} {...} {...}
应修改为:
[{...},{...},{...}]
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 1In 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"
}
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:[{...},{...},{...}]
这篇关于完整日历不显示来自JSON源的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!