问题描述
我一直试图在fullcalendar中重复发生的事件,我真的觉得dow功能很有用,但我真的想为它添加日期范围。换句话说,换句话说, ,dow:[1]会为每个星期一重复一个任务,问题是,我想只在我设置的日期范围内才能看到它。
您无法使用dow设置范围,您必须执行一些自定义功能。
让我们假设您已经从包含多个事件对象的数据库中提取事件数据。每个事件
对象都有 start
date end
date属性, 至
和来自
包含日期范围的属性, isRecurring
是一个布尔属性,我们将在循环事件的情况下添加 true
,否则它将是 false
。 start =16:00and end =20:00在初始化我的事件对象时,您可以使用像我一样的时刻js来提取时间
{
title:'Recurring Event',
start:moment.utc(event.start).format('HH:mm'),
end:moment.utc(event.end).format('HH:mm'),
isRecurrring:event.isRecurring,
ranges:[{
start:moment(event。 from),
end:moment(event.to),
}],
}
我使用了moment.utc()来忽略时区。
现在在初始化fullCalendar时覆盖eventRender函数。您的eventRender函数将是
eventRender:function(event,element,view){
if(event.isRecurrring) {
return(event.ranges.filter(function(range){
return(moment(event.start).isBefore(range.end)&&
moment(event.end ).isAfter(range.start));
})。length)> 0;
}
}
I have been trying to make recurring events in fullcalendar, I really find dow feature helpful, but I really want to add date ranges to it.
In other words, dow : [1] will repeat a task for every single Monday, the problems is, I want to make it visible only in a date range I set.
You can not set ranges by using dow, you have to perform some custom functionality.
Lets suppose that you have fetched events data from your database which contains multiple event objects. each event
object has start
date end
date property and also to
and from
properties which contains date range , isRecurring
is a Boolean property which we will add true
in case of recurring events otherwise it will be false
.
Remember the recurring events take start and end time without date, you only need to give them time slots, like start = "16:00" and end = "20:00"
You can extract time by using moment js like i did while initializing my event object
{
title:'Recurring Event',
start: moment.utc(event.start).format('HH:mm'),
end: moment.utc(event.end).format('HH:mm'),
isRecurrring: event.isRecurring,
ranges: [{
start: moment(event.from),
end: moment(event.to),
}],
}
I have used moment.utc() to ignore the timezone.
Now override the eventRender function while initializing your fullCalendar. Your eventRender function will be
eventRender: function(event, element, view){
if (event.isRecurrring) {
return (event.ranges.filter(function(range){
return (moment(event.start).isBefore(range.end) &&
moment(event.end).isAfter(range.start));
}).length) > 0;
}
}
这篇关于Fullcalendar经常性事件限制(使用dow)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!