我试图计算全典型每日事件中的总数,以停止在限制达到4
的任何特定日期预订的更多事件。
这是我所拥有的,在每日事件达到4
时可以正常工作,但超过了qty
。
var eventCounter = 0;
$('#calendar').fullCalendar('clientEvents', function(event) {
if(moment(start).format('YYYY-MM-DD HH:mm:ss') == event.start.format('YYYY-MM-DD HH:mm:ss')) {
eventCounter++;
}
});
if(eventCounter < 4) {
$('#ModalAdd #start').val(moment(start).format('YYYY-MM-DD HH:mm:ss'));
$('#ModalAdd #end').val(moment(end).format('YYYY-MM-DD HH:mm:ss'));
$('#ModalAdd').modal('show');
} else {
swal({
title: "Maximum Bookings",
text: "Sorry, the maximum number of bookings are taken for this day. Please select another date.",
type: "warning"
});
}
我想要的是每天event[]
的qty
计数,而不是事件。
事件数组的示例;
events: [
{
id: '233',
title: 'Tandem Jump',
qty: '4',
start: '2016-11-29 00:00:00',
end: '2016-11-29 00:00:00'
},
{
id: '239',
title: 'Tandem Jump',
qty: '2',
start: '2016-11-30 00:00:00',
end: '2016-11-30 00:00:00'
},
]
我不确定这是否是您需要的,但这将计算一天之后的给定一天之内的事件数量(单击一个月查看):
$('#calendar').fullCalendar({
weekends: true,
defaultView: 'month',
allDaySlot: false,
header: {
left: 'month,agendaWeek,agendaDay,listDay',
center: 'title',
right: 'prev,next today'
},
events: [{
title: 'event 1',
start: '2016-12-05T16:00:00',
end: '2016-12-05T18:00:00'
}, {
title: 'event 2',
start: '2016-12-05T18:00:00',
end: '2016-12-05T20:00:00'
}, {
title: 'event 3',
start: '2016-12-07T16:00:00',
end: '2016-12-07T18:00:00'
}, {
title: 'event 7',
start: '2016-12-07T12:00:00',
end: '2016-12-07T14:00:00'
}, {
title: 'event 4',
start: '2016-12-07T11:00:00',
end: '2016-12-07T12:00:00'
}, {
title: 'event 5',
start: '2016-12-08T16:00:00',
end: '2016-12-08T18:00:00'
}],
height: 'auto',
editable: true,
dayClick: function(date, allDay, jsEvent, view) {
if (!allDay) {
// strip time information
date = new Date(date.getFullYear(), date.getMonth(), date.getDay());
}
var ar = $('#calendar').fullCalendar('clientEvents', function(event) {
if (event.start.year() == date.year() && event.start.month() == date.month() && event.start.day() == date.day()) {
return true;
}
return false;
});
console.log(ar.length);
}
});
https://jsfiddle.net/jzajf4e8/