我使用FullCalendar和Date.js来设置每周议程。我也使用fullCalendar jQuery, repeat every monday?的答案来反复发生事件 - 但我很难将这些事件转换为特定的时间,而不是整天。
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
defaultView: 'agendaWeek'
});
// adding a every monday and wednesday events:
$('#calendar').fullCalendar( 'addEventSource',
function(start, end, callback) {
// When requested, dynamically generate virtual
// events for every monday and wednesday.
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().monday()) {
events.push({
title: 'Meeting',
start: test_date
});
}
} // for loop
// return events generated
callback( events );
}
);
我试过改变&#34; if&#34;检查时间也没有运气,我已经尝试设置test_date变量的时间,但没有成功。
我很感激帮助。
答案 0 :(得分:1)
谢谢,sulaiman,这很有帮助。我还不得不抛弃date.js - 它不再处于开发状态,许多功能都被打破了。这是我达到的完整解决方案。
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
defaultView: 'agendaWeek',
defaultEventMinutes: 45,
editable: false
});
$('#calendar').fullCalendar( 'addEventSource',
function(start, end, callback) {
// When requested, dynamically generate virtual events for every monday and wednesday.
var events = [];
// checks every 30 minutes, rather than 24 hours
for (loop = start.getTime(); loop <= end.getTime(); loop = loop + (30 * 60 * 1000)) {
var test_date = new Date(loop);
if (test_date.getDay() === 1 && test_date.getHours() === 11 && test_date.getMinutes() === 30){
events.push({
title: 'Meeting',
start: test_date
allDay: false
});
}
} // for loop
// return events generated
callback( events );
}
);
答案 1 :(得分:0)
您必须添加allDay: false
if (test_date.is().monday()) {
events.push({
title: 'Meeting',
start: test_date,
allDay: false
});
}