渲染JSON事件的完整日历
问题描述:
我试图呈现从JSON响应fullcalendar事件,渲染JSON事件的完整日历
$.ajax({
url : $("body").attr("data-link")+'/calendar/events',
type : 'post',
dataType: 'json',
success: function(e){
if(e.success){
var events = [];
$.each(e.events,function(index,value){
events.push({
title : value.title,
start : moment(value.start_date).format('YYYY-MM-DD'),
end : moment(value.end_date).format('YYYY-MM-DD'),
});
});
calendar.fullCalendar('renderEvent', events , true);
console.log(events);
}
}
});
这里是我的fullcalendar设立
var calendar = $('#calendar').fullCalendar({
customButtons: {
myCustomButton: {
text: 'Add Event',
click: function() {
}
}
},
header: {
left: 'prev,next today myCustomButton',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable : false,
eventLimit: true,
eventClick: function(calEvent, jsEvent, view, element) {
},
eventRender: function(event, element) {
element.attr("data-id",event.id);
},
});
在控制台日志。
,然后它给了我这个错误,
Uncaught TypeError: Cannot read property 'hasTime' of undefined
任何想法,帮助吗?
答
你既可以调用renderEvent
每个事件events
或添加整个阵列作为数据源
$.ajax({
url : $("body").attr("data-link")+'/calendar/events',
type : 'post',
dataType: 'json',
success: function(e){
if(e.success){
var events = [];
$.each(e.events,function(index,value){
events.push({
title : value.title,
start : moment(value.start_date).format('YYYY-MM-DD'),
end : moment(value.end_date).format('YYYY-MM-DD'),
});
});
calendar.fullCalendar('addEventSource', events);
}
}
});
+0
对,这就是我现在使用的,谢谢! –
+1
顺便说一句,你可以使用函数作为事件源。 [文件](http://fullcalendar.io/docs/event_data/events_function/)。 –
没有日志,控制台看起来是正确的? –
是的,在控制台日志中,其正确的 –
'console.log(events);'是否正确打印所有事件? –