我试图找出如何处理日历事件与Google日历的重叠方式。 我有一系列包含开始和结束日期的事件。
目前,我将整个数组按照从最早到最晚的顺序排序,然后找出事件重叠的次数以及重叠事件的次数。我不知道从哪里开始,我觉得我可以使用这些值来计算正确的css宽度%和左边%。我甚至走在正确的轨道上?我作为一个学校项目这样做。提前谢谢!
编辑:我看了一下Markus Jarderot之前回答过的类似问题,并找到了我想要的答案。非常感谢你!function getOverlappingEvents(eventArray) {
var result = [];
eventArray.sort(function(a, b) {
return a.eventStart - b.eventStart;
});
for (var i = 0; i < eventArray.length; i++) {
var overapped = 0;
var overlaps = 0;
var isdate = new Date(eventArray[i].eventStart);
var iedate = new Date(eventArray[i].eventEnd);
for (var x = 0; x < eventArray.length; x++) {
var xsdate = new Date(eventArray[x].eventStart);
var xedate = new Date(eventArray[x].eventEnd);
if(isdate <= xsdate && iedate > xsdate){
overapped++;
}else if(isdate >= xsdate && isdate < xedate){
overlaps++;
}
}
result.push([eventArray[i].calEventID, overapped, overlaps]);
}
return result;
}
function toDom(events, ids){
var domEvents = [];
for (var i = 0; i < events.length; i++) {
var id = events[i].calEventID;
var width = 0;
var left = 0;
var sDate = new Date(events[i].eventStart);
var eDate = new Date(events[i].eventEnd);
var time = sDate.format("htt") + " - " + eDate.format("htt");
var duration = (eDate.getHours() * 60 + eDate.getMinutes()) - (sDate.getHours() * 60 + sDate.getMinutes());
var height = Math.round((duration * 0.75));
var topOffSet = (sDate.getHours() - 6) * 45 + Math.round(sDate.getMinutes() * 0.75);
var status = events[i].calStatus;
var desc = events[i].description;
var json = {id: id, sDate: sDate, eDate: eDate, status: status, height: height+"px", top: topOffSet+"px", width: width+"%", left: left+"%", desc: desc, time: time};
console.log(json);
domEvents.push(json);
}
return domEvents;
}