将自定义参数添加到fullcalendar请求

我想在检索事件数据时fullcalendar提交的请求中添加一个名为foo的参数。 根据文档,这可以通过以下方式实现:

 var getFoo() = function() { // implementation omitted }; $('#calendar').fullCalendar({ loading: function(isLoading) { // CAN I SOMEHOW UPDATE foo FROM HERE? }, events: { url: '/myfeed.php', type: 'POST', data: { foo: getFoo() } } }); 

我希望每次请求日历事件数据时计算foo参数的值,但似乎fullcalendar仅在第一次加载时调用getFoo() ,然后为每个后续请求重新使用该值。

我已经尝试使用这个在loading数据之前立即触发的loading事件,但是我无法弄清楚如何从这个函数中更新foo参数。

更新

我按照下面的建议进行了处理:

  $('#calendar').fullCalendar({ events: function(start, end, callback) { $.ajax({ url: 'getCalendarEvents', dataType: 'json', data: { start: Math.round(start.getTime() / 1000), end: Math.round(end.getTime() / 1000), foo: getFoo() }, success: function(doc) { var events = eval(doc); callback(events); } }); }, }); 

也许你可以使用事件作为函数来创建自己的ajax请求。

 var getFoo() = function() { // implementation omitted }; $('#calendar').fullCalendar({ events: function(start, end, callback) { var myFoo = getFoo(); $.ajax({ url: 'myxmlfeed.php', dataType: 'xml', data: { // our hypothetical feed requires UNIX timestamps start: Math.round(start.getTime() / 1000), end: Math.round(end.getTime() / 1000), foo: myFoo }, success: function(doc) { var events = []; $(doc).find('event').each(function() { events.push({ title: $(this).attr('title'), start: $(this).attr('start') // will be parsed }); }); callback(events); } }); } }); 

尝试将lazyFetching设置为false。 我猜你有这个问题因为fullCalendar试图让你免于不必要的ajax请求。

关于lazyFetching的Fullcalendar文档