如何fullcalendar fc事件削减 [英] How to fullcalendar fc-event cut
本文介绍了如何fullcalendar fc事件削减的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
虽然暴露日历时fc事件中的事件暴露于日历,但我们希望防止时间,土壤和星期天的表达。有没有办法....?
举例:
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ ↓↓↓↓↓↓↓↓↓↓↓
解决方案
您可以将事件开始/结束并将其分解为多个部分。 $ b https://jsfiddle.net/31gayu5b/4/
/ * Fiddle specs:fullcalendar v2.4.0,moment v2.10.6,jQuery v2.1.4 * /
/ *如果排印是真的,则将周六,周日剪掉* /
var events = [{
start:'2016-02-01',
结尾:'2016-03-01',
title:'这是整整一个月的时间,没有周末!',
id:'month-long-no-weekends',
chop :true
},{
start:'2016-02-01',
end:'2016-03-01',
title:'这是整整一个月,包括周末!',
id:'月长周末',
截断:false
},{
开始:'2016-02-07',
结束:'2016-02-16',
标题:'开始星期天结束星期二(无周末)',
id:'start-sun-no-weekends',
chop:true
},{
start:'2016-02-07',
end:'2016-02-16',
title:'开始周日结束星期二(有周末)',
id:'start-sun-weekends',
chop:false
}];
$ b $('#calendar')。fullCalendar({
defaultDate:'2016-02-01',
events:chopEvents(events),
eventClick:函数(event,jsEvent,view){
alert(event.id);
},
eventRender:function(event,element,view){
console.log(event );
if(event.chop)
element.css('background-color','green');
}
});
函数chopEvents(事件){
var chopped = [];
$(events).each(function(){
var event = this;
if(this.chop){
var segments = makeChunks(this);
$(segments).each(function(index,dates){
var start = dates.shift();
var end = dates.pop();
event.start = start ;
event.end = end;
chopped.push($。extend({},event));
});
} else {
chopped。推(事件);
}
});
回报斩获;
}
函数makeChunks(event){
var seg = 0;
var segments = [];
var start = moment(event.start);
var end = moment(event.end); //.add(1,'day'); / *可能要添加1天? * /
for(var day = moment(start); day <= end; day = day.add(1,'day')){
var dayOfWeek = day.format('E' );
if(dayOfWeek == 7){
segments [++ seg] = [];
继续;
}
if(segments [seg] === undefined){
segments [seg] = [];
}
segments [seg] .push(day.format('YYYY-MM-DD'));
}
segments = segments.filter(function(i){
return i!== null&& i.length> 1;
})
// console.log(JSON.stringify(segments,null,2));
返回细分;
}
The fullcalendarAPI is in use . This will write a sentence if there is a question of being developed . Although events in the fc-event when you expose the calendar is exposed to the calendar , we want to prevent that time , the soil , the expression on Sunday . Is there a way....?
example :
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
解决方案
You can take the events start/end and break it up into sections.
https://jsfiddle.net/31gayu5b/4/
/* Fiddle specs: fullcalendar v2.4.0, moment v2.10.6, jQuery v2.1.4 */
/* If chop is true, it cuts out Saturday, Sunday */
var events = [{
start: '2016-02-01',
end: '2016-03-01',
title: 'This is the whole month long, no weekends!',
id: 'month-long-no-weekends',
chop: true
}, {
start: '2016-02-01',
end: '2016-03-01',
title: 'This is the whole month long, including weekends!',
id: 'month-long-weekends',
chop: false
}, {
start: '2016-02-07',
end: '2016-02-16',
title: 'Starts Sunday ends Tuesday the week after (no weekends)',
id: 'start-sun-no-weekends',
chop: true
}, {
start: '2016-02-07',
end: '2016-02-16',
title: 'Starts Sunday ends Tuesday the week after (has weekends)',
id: 'start-sun-weekends',
chop: false
}];
$('#calendar').fullCalendar({
defaultDate: '2016-02-01',
events: chopEvents(events),
eventClick: function(event, jsEvent, view) {
alert(event.id);
},
eventRender: function(event, element, view) {
console.log(event);
if (event.chop)
element.css('background-color', 'green');
}
});
function chopEvents(events) {
var chopped = [];
$(events).each(function() {
var event = this;
if (this.chop) {
var segments = makeChunks(this);
$(segments).each(function(index, dates) {
var start = dates.shift();
var end = dates.pop();
event.start = start;
event.end = end;
chopped.push($.extend({}, event));
});
} else {
chopped.push(event);
}
});
return chopped;
}
function makeChunks(event) {
var seg = 0;
var segments = [];
var start = moment(event.start);
var end = moment(event.end); //.add(1, 'day'); /* May want to add 1 day? */
for (var day = moment(start); day <= end; day = day.add(1, 'day')) {
var dayOfWeek = day.format('E');
if (dayOfWeek == 7) {
segments[++seg] = [];
continue;
}
if (segments[seg] === undefined) {
segments[seg] = [];
}
segments[seg].push(day.format('YYYY-MM-DD'));
}
segments = segments.filter(function(i) {
return i !== null && i.length > 1;
})
// console.log(JSON.stringify(segments, null, 2));
return segments;
}
这篇关于如何fullcalendar fc事件削减的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文