[英]FullCalendar: Add an event by the day of the week
I'm building a grade school, I have a bunch of disciplines and it's day of the week
. 我正在建一所小学,我有很多学科,现在day of the week
。 I need to insert these disciplines into the calendar. 我需要将这些学科插入日历中。 The problem is: 问题是:
There is no way to add only by the day of the week
. 无法仅day of the week
。 See: 看到:
Today is Sunday( 04/09/2016 ). 今天是星期日(04/09/2016)。 But the calendar days are from the PAST week. 但是日历天是从PAST周开始的。
So, if you have: 因此,如果您有:
var day = 'monday';
When you are going to insert an event in runtime
you'd do like so: 当您要insert an event in runtime
您会这样做:
$('#calendario').fullCalendar(
'renderEvent',
{
id: id
title: $(this).find('a').text(),
start: year+ '-' +month+ '-' +day+ 'T' + startTime,
end: year+ '-' +month+ '-' +day+ 'T' + endTime,
backgroundColor: color,
className: someClass
}
)
As you can see, I HAVE TO specify day
of the month. 正如你所看到的,我必须指定day
的一个月。
The problem is: Even using weekView
, I can't work with events using only week days... I have to give the entire date(YYYY-MM-DD). 问题是:即使使用weekView
,我也不能仅使用weekView
来处理事件...我必须给出整个日期(YYYY-MM-DD)。
Today is sunday(04/09/2016). 今天是星期日(04/09/2016)。 The calendar is half last month, half current month. 日历是上个月的一半,本月的一半。 How am I supposed to insert an event only by the day of the week
? 我应该如何只day of the week
插入事件?
Also tried working with momentjs
. 还尝试过使用momentjs
。
moment().day(1).hours(10).minutes(0).format('YYYY-MM-DD')
moment will return the second day of the week (0 - sunday, 1 - monday ), wich is 05 (currently week) and not the same as fullCalendar 29(last week). moment将返回一周的第二天(0-星期日,1-星期一),至于05(当前星期),与fullCalendar 29(上周)不同。 So I have no Idea how to insert my disciplines/events into the calendar. 因此,我不知道如何将我的学科/事件插入日历。
You can provide events as a function and loop through the time period currently displayed, creating events on specific days 您可以提供事件功能,并循环显示当前显示的时间段,从而在特定日期创建事件
https://jsfiddle.net/0roafa2f/ https://jsfiddle.net/0roafa2f/
$('#calendar').fullCalendar({
events: dowEvents
});
function dowEvents(start, end, tz, callback) {
var events = [];
var curr = start;
while(curr <= end) {
if(curr.format('dddd') === 'Monday') {
events.push({
title: 'Monday event',
start: moment(curr)
});
}
curr = curr.add(1, 'day');
}
callback(events);
}
According to the source code of the demo on this page: https://fullcalendar.io/ meanwhile, events is an array object that can be listed manually, fetched from a url with json response or fetched from a function as stated here: https://fullcalendar.io/docs/event-data 根据此页面上演示的源代码: https : //fullcalendar.io/,同时,事件是一个数组对象,可以手动列出,可以从带有json响应的url中获取,也可以从如下所述的函数中获取: https ://fullcalendar.io/docs/event-data
$(function() {
var todayDate = moment().startOf('day');
var YM = todayDate.format('YYYY-MM');
var YESTERDAY = todayDate.clone().subtract(1, 'day').format('YYYY-MM-DD');
var TODAY = todayDate.format('YYYY-MM-DD');
var TOMORROW = todayDate.clone().add(1, 'day').format('YYYY-MM-DD');
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay,listWeek'
},
editable: true,
eventLimit: true, // allow "more" link when too many events
navLinks: true,
events: [
{
title: 'All Day Event',
start: YM + '-01'
},
{
title: 'Long Event',
start: YM + '-07',
end: YM + '-10'
},
{
id: 999,
title: 'Repeating Event',
start: YM + '-09T16:00:00'
},
{
id: 999,
title: 'Repeating Event',
start: YM + '-16T16:00:00'
},
{
title: 'Conference',
start: YESTERDAY,
end: TOMORROW
},
{
title: 'Meeting',
start: TODAY + 'T10:30:00',
end: TODAY + 'T12:30:00'
},
{
title: 'Lunch',
start: TODAY + 'T12:00:00'
},
{
title: 'Meeting',
start: TODAY + 'T14:30:00'
},
{
title: 'Happy Hour',
start: TODAY + 'T17:30:00'
},
{
title: 'Dinner',
start: TODAY + 'T20:00:00'
},
{
title: 'Birthday Party',
start: TOMORROW + 'T07:00:00'
},
{
title: 'Click for Google',
url: 'http://google.com/',
start: YM + '-28'
}
]
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.