添加自定义参数到fullcalendar请求 [英] add custom params to fullcalendar request
问题描述
我想向检索事件数据时fullcalendar提交的请求添加一个名为 foo
的参数。根据,这可以通过以下方式实现:
I'm want to add a parameter named foo
to the request that fullcalendar submits when retrieving event data. According to the docs this can be achieved using:
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()
,然后将该值重新用于每个后续请求。
I want the value of the foo
parameter to be calculated each time the calendar event data is requested, but it seems that fullcalendar only calls getFoo()
the first time it loads, then re-uses that value for each subsequent request.
我试过使用这个加载
事件,它在数据加载之前立即触发,但我无法弄清楚如何更新这个函数中的 foo
参数。
I've tried using this the loading
event that is triggered immediately before the data is loaded, but I can't figure out how to update the foo
paramter from within this function.
我遵循下面的建议,并使用它:
I followed the advice below and got it working with this:
$('#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);
}
});
},
});
推荐答案
也许你可以使用 events as function 创建您自己的ajax请求。
Maybe you could use the events as function to create your own ajax request.
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);
}
});
}
});
这篇关于添加自定义参数到fullcalendar请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!