我需要在我的日历上为所有星期日添加一个活动。 FullCalendar中有没有可用的选项?
day = 'Sunday'; <------ I need to pass this day to create event
var date = new Date();
var event = {id: result.id, title: from_time + '-' + to_time, start: new Date(date), allDay: false};
}
$('#calendar').fullCalendar('renderEvent', event, true);
您可以使用dow
事件属性非常简单地完成此操作。它没有很好地记录,但它在backgroundEvents
和businessHours
中提到过。它允许您设置事件始终发生的星期几。
所以像这样:
$("#calendar").fullCalendar({
events:[{
title:"Monday",
dow:[1] //monday
//start/endtime works too
},{
title:"background",
dow:[2,3], //tuesday and wednesday
rendering: 'background'
}],
});
如果你需要更复杂的东西,比如只在某个日期范围内重复活动,请看看我的答案:https://stackoverflow.com/a/29393128/728393
请查找一些事件重复的参考代码。
$('#calendar').fullCalendar( 'addEventSource',
function(start, end, callback) {
// When requested, dynamically generate virtual
// events for every sunday
var events = [];
for (loop = start.getTime();
loop <= end.getTime();
loop = loop + (24 * 60 * 60 * 1000)) {
var test_date = new Date(loop);
if (test_date.is().sunday()) {
// we're in Sunday, create the event
events.push({
title: 'I Love Sundays - Janty',
start: test_date
});
}
} // for loop
// return events generated
callback( events );
}
);
events: [
{
title:"Monday",
dow:[1] //monday
//start/endtime works too
},{
title:"background",
*daysOfWeek*: [2, 3], //tuesday and wednesday
rendering: 'background'
}]