Javascript 删除Fullcalendar中一天中未使用的小时数
我正在尝试配置Fullcalendar以管理夜间事件。因此,我有一天开始,第二天早上结束的环境。 因此,目前我有以下配置:Javascript 删除Fullcalendar中一天中未使用的小时数,javascript,jquery,json,fullcalendar,Javascript,Jquery,Json,Fullcalendar,我正在尝试配置Fullcalendar以管理夜间事件。因此,我有一天开始,第二天早上结束的环境。 因此,目前我有以下配置: { header: { left: '', center: 'title', right: '' }, defaultView: 'timelineTwoDays', views: { timelineTwoDays: { type: 'timeline'
{
header: {
left: '',
center: 'title',
right: ''
},
defaultView: 'timelineTwoDays',
views: {
timelineTwoDays: {
type: 'timeline',
duration: { days:1, hours:7, minutes:00 }
}
},
scrollTime: '17:00'
}
这不是最好的解决方案,因为指定的滚动时间之前的小时是隐藏的,但我想完全删除它们
minTime
不是一个选项,因为它还删除了午夜后的小时数。理想情况下,您应该将此设置为一个。但这里有一个简单的方法
伪造时间段标签
在上,抓住插槽标签并向其添加偏移:
viewRender: function (view, element) {
if (view.name.indexOf("timeline") > -1) { //if it's a timeline view
$(element).find(".fc-chrono .fc-cell-text").each(
function (i, cell) {
var old = moment($(cell).text(), "ha"); //grab and parse old time label
$(cell).text(old.add(OFFSET, 'h').format("ha")); //add an offset
}
);
}
},
并设置。记住,有一个偏移量
minTime: "15:00:00", //is actually 15h + offset
问题 这自然会引起一些问题
- 它只会更改标签。FC仍然认为标记为
的地方是午夜5am
- 服务器同步问题。您必须存储偏移日期或将其从服务器转换到服务器
- 日期标签可能不是您想要的。他们将在同一天显示类似于晚上10点到凌晨4点的内容
辅助函数 像这样的东西会有用的。将事件转换为偏移事件并再次转换
var offset = {
_offset: 6, //in hours
_apply: function(moments,op){ //sub/add offset from moment array, with null checks
for(var i = 0; i < moments.length; i++){
if(moment.isMoment(moments[i]))
moments[i][op](this._offset,'h');
}
},
get: function(){
return this._offset;
},
//Add the offset to the event or moment
//Real time/display time -> offset timeline time
add: function(event){
this._apply([event,event.start,event.end],'subtract');
return event;
},
//Remove the offset to the event or moment
//Offset timeline time -> real time/display time
remove: function(event){
this._apply([event,event.start,event.end],'add');
return event;
}
};
var偏移={
_偏移量:6,//以小时为单位
_应用:函数(矩,op){//sub/添加矩数组的偏移量,带有空检查
对于(var i=0;i偏移时间线时间
添加:功能(事件){
这个._应用([event,event.start,event.end],'subtract');
返回事件;
},
//删除对事件或时刻的偏移
//偏移时间轴时间->实时/显示时间
删除:函数(事件){
这个._apply([event,event.start,event.end],'add');
返回事件;
}
};
所以你想从每天的中间抽出一大块时间吗?如果这是正确的,就没有一种内在的方式。不过,我也许可以一起破解一些东西。Thx@slicedtoad。今晚我会检查你的解决方案,我会让你知道。。。然而+1。。。