我使用事件 url 从数据库检索事件,但事件未显示在 fullcalnder 中?
我的Js代码是
$('#inspectionCalendar').fullCalendar({
header: {
left: 'next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
editable: false,
eventLimit: true, // allow "more" link when too many events
events: '<?php echo base_url(); ?>inspections/inspections_record',
});
我的 Controller 操作是:
function inspections_record() {
echo "[
{
title: 'All Day Event',
start: '2015-08-01'
},
{
title: 'Long Event',
start: '2015-02-07'
},
{
id: 999,
title: 'Repeating Event',
start: '2015-08-09T16:00:00'
},
{
id: 999,
title: 'Repeating Event',
start: '2015-08-16T16:00:00'
},
{
title: 'Conference',
start: '2015-08-26'
},
{
title: 'Meeting',
start: '2015-08-25T10:30:00',
},
{
title: 'Lunch',
start: '2015-08-25T12:00:00'
},
{
title: 'Meeting',
start: '2015-08-25T14:30:00'
},
{
title: 'Happy Hour',
start: '2015-08-12T17:30:00'
},
{
title: 'Dinner',
start: '2015-08-12T20:00:00'
},
{
title: 'Birthday Party',
start: '2015-08-13T07:00:00'
},
{
title: 'Click for Google',
url: 'http://google.com/',
start: '2015-08-28'
}
],";
}
我的浏览器控制台显示响应,但事件未显示在日历中?
请帮助我。
谢谢
最佳答案
我认为您应该删除正在回显的 JSON
末尾的逗号,就在 ]
之后。您还必须用双引号而不是单引号将 json 中的名称和值引起来。这将使 inspections_record()
看起来像:
function inspections_record() {
echo '[
{
"title": "All Day Event",
"start": "2015-08-01"
},
{
"title": "Long Event",
"start": "2015-02-07"
},
{
"id": 999,
"title": "Repeating Event",
"start": "2015-08-09T16:00:00"
}
etc...
]';
}
结论:您提供给日历的事件 JSON
不是有效的 JSON
。这将导致日历不显示您的事件。
关于javascript - 使用 codeigniter 事件未显示在完整日历中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32197393/