Jos*_*osh 3 jquery fullcalendar
我正在提取查看月份的Fullcalendar数据。当我单击“下一个/上一个月”视图按钮时,它不会熄灭并获取新月份的新数据。
如何获得“下一个/上一个”按钮来再次调用数据库并提取该月的记录?
定义事件回调以向您的api发出ajax请求。在此处查看文档。这是与我的api集成的示例,该api使用时期开始和结束作为查找中的get参数。
$('#calendar').fullCalendar({
// other options here...
events: function(start, end, callback) {
start = start.getTime()/1000;
end = end.getTime()/1000;
$.ajax({
url: '/api/events/1/?start='+ start + '&end=' + end,
dataType: 'json',
success: function(doc) {
var my_events = [];
$.each(doc.person.events, function (index, elem) {
my_events.push({
title: elem.event.title,
start: elem.event.start,
end: elem.event.end,
});
});
callback(my_events);
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
在我的实际代码(这是精简版)中,我对ajax请求做了更多工作。您还可以使用fullcalendar的json feed事件简化此过程,该事件将传递开始和结束时期的日期为您获取参数。例如:
$('#calendar').fullCalendar({
events: "/api/events/1/"
});
Run Code Online (Sandbox Code Playgroud)
这两个解决方案都将像对服务器一样进行api调用,http://yourwebsite.com/api/events/1/?start=123454444&end=12355324234因此您需要设置服务器以适当地处理它。
注意:如果您想知道,这些URL中的“ 1”用于标识要为其获取事件的用户的ID。
fullcalendar 的文档很棒,请阅读它们,然后再次阅读。