gpt4 book ai didi

jquery - 如何限制全日历中每个时间段的事件?

转载 作者:行者123 更新时间:2023-12-01 05:49:02 25 4
gpt4 key购买 nike

是否可以限制FullCalendar-2仅在槽间隔内添加事件并将其限制为 2?

例如,用户只能在12:00:00 - 12:15:00之间添加事件,不可能添加更长的事件(12:00:00 - 12:30:00),他可以添加它仅当有“免费”插槽时。橙色事件是正确的(时间段内最多2个事件),蓝色事件是错误的(超过2个事件)

这是一个例子

$(document).ready(function() {

// page is now ready, initialize the calendar...

$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'agendaDay'
},
defaultView: 'agendaDay',
allDaySlot: false,
scrollTime: moment().format('HH:mm:ss'),
slotDuration: '00:15:00',
minTime: '06:45:00',
maxTime: '23:15:00',
editable: true,
events: [
{
title: 'Meeting',
start: '2014-06-06T10:30:00',
end: '2014-06-06T10:45:00'
},
{
title: 'Lunch',
start: '2014-06-06T10:30:00',
end: '2014-06-06T10:45:00'
},
{
title: 'Birthday Party',
start: '2014-06-06T10:30:00',
end: '2014-06-06T10:45:00'
},
{
title: 'Meeting',
start: '2014-06-06T15:30:00',
end: '2014-06-06T15:45:00',
color: '#FF7F50'
},
{
title: 'Lunch',
start: '2014-06-06T15:30:00',
end: '2014-06-06T15:45:00',
color: '#FF7F50'
}
]

});

});

并直播:http://jsbin.com/fezidowo/3/

最佳答案

select: function(start, end) {
console.log( 'Events :' + getEventsByTime( start, end ).length );
var ev = getEventsByTime( start, end );
console.log( ev );
var itms = {};

ev.forEach(function(entry){

var begin = moment(entry.start);
var final = moment(entry.end);


while( begin.diff(final) < 0 ) {
itms[begin] = ( itms[begin] || 0) + 1;
if( itms[begin] >= maxEventsInInterval ) {
console.log(' __ WARNING __ , max events exceeded! ');
}

begin = moment(begin).add('seconds', 900);
}

});
console.log( itms );
}

function getEventsByTime( start, stop ) {
var todaysEvents = $('div[name=calendar]').fullCalendar('clientEvents', function(event) {

return (
( event.start >= start && event.end <= stop ) ||
( start >= event.start && stop <= event.end) ||
(start <= event.start && stop >= event.start) ||
(start >= event.start && start <= event.end)
);
});
return todaysEvents;
}

关于jquery - 如何限制全日历中每个时间段的事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24077098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com