[英]Specify data for Fullcalendar's eventSources
I am using the jQuery Fullcalendar plugin. 我正在使用jQuery Fullcalendar插件。 On the same page, I have a form with checkboxes which are used to filter the event data fetched from the server.
在同一页面上,我有一个带有复选框的表单,用于过滤从服务器获取的事件数据。 The idea is that I want to pass those form values into the
eventSources
object, so that they get transmitted to the server together with the start/end timestamps. 我的想法是,我想将这些表单值传递到
eventSources
对象中,以便它们与开始/结束时间戳记一起传输到服务器。
The docs have a sample eventSources
object like this: 该文档具有一个示例
eventSources
对象,如下所示:
$('#calendar').fullCalendar({
eventSources: [
// your event source
{
url: '/myfeed',
type: 'POST',
data: {
custom_param1: 'something',
custom_param2: 'somethingelse'
},
}
// other sources...
]
});
Which I modified to: 我修改为:
eventSources: [
{
// ...as above
data: getFormAsObject(),
// as above...
}
I want the form's values to get passed into the the data
object. 我希望将表单的值传递到
data
对象中。 In the getFormAsObject()
function, I serialize the form and convert that to an associative array. 在
getFormAsObject()
函数中,我序列化表单并将其转换为关联数组。
All that is left is to hijack the form submission. 剩下的就是劫持表单提交了。 So if the "submit" button is clicked, I cancel the default POST action, and call
因此,如果单击“提交”按钮,我将取消默认的POST操作,然后调用
calendar.fullCalendar("refetchEvents");
BUT, this doesn't work, and the getFormAsObject()
doesn't get called at all. 但是,这不起作用,并且根本不调用
getFormAsObject()
。 What am I doing wrong? 我究竟做错了什么?
Problem is (it seems) that Fullcalendar only reads that data
object once. 问题是(似乎)Fullcalendar仅读取一次该
data
对象。 So it reads it the first time and then not again, even if I set it to a function. 因此,即使我将其设置为函数,它也会第一次读取,然后再读取一次。 I'm not certain, but I think it may be how the underlying
ajax()
call works? 我不确定,但是我认为这可能是底层
ajax()
调用的工作方式?
So I've changed it to remove the eventSources
and then readd new ones every time I do an update. 因此,我已对其进行了更改,以删除
eventSources
,然后每次进行更新时都eventSources
新内容。 Seems ugly, but works. 看起来很丑,但是行得通。
Use the "Dynamic data parameter" Second last option here: https://fullcalendar.io/docs/events-json-feed 在此处使用“动态数据参数”倒数第二个选项: https : //fullcalendar.io/docs/events-json-feed
$('#calendar').fullCalendar({
events: {
url: '/myfeed.php',
data: function() { // a function that returns an object
return {
dynamic_value: Math.random()
};
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.