3

我已经实现了 fullcalendar v2 资源日历。我无法解决的是基于天设置动态minTimemaxTime 。每天都有不同的工作时间。

周一 10:00 至 14:00

周二 16:00 至 24:00 ...

我以这种方式初始化了我的日历:

$('#calendar').fullCalendar({
header: {
    left: 'prev,next today',
    center: 'title',
    right: 'month,agendaWeek,resourceDay'
},
defaultView: 'resourceDay',
titleFormat: {'day':'dddd, MMMM D'},
minTime: "08:00",
maxTime: "20:00",
scrollTime:  moment().format('H:m'),
eventLimit: true, // allow "more" link when too many events
resources:[
    resource1,resource2
    ],
slotDuration: '00:15:00',
allDaySlot: false,
lazyFetching: false,
droppable: true,
defaultTimedEventDuration: '00:30:00',
selectable: true,
selectHelper: true,
unselectAuto: 'true',
timeFormat: {'agenda':'hh:mm A','':'hh:mm A'},

// Calender Method-1: AJAX events will loaded from this code
events:function(start, end, timezone,callback) {

$.ajax({
        url: "http://www.domainn.com/dashboard/index",
        dataType: 'json',
        type:'POST',
        // async: false, //blocks window close
        data: {
            start: start.unix(),
            end: end.unix(),
            viewtype: $('#calendar').fullCalendar('getView').name,
        },
        success:function(response){
          var calendarOptions = $('#calendar').fullCalendar('getView').calendar.options;
          // console.log(calendarOptions);
         calendarOptions.minTime = response.timings.start;
          calendarOptions.maxTime = response.timings.end;

          $('#calendar').fullCalendar('destroy');

          $("#calendar").fullCalendar(
                $.extend(calendarOptions, {
                    events:response.resources
                })
          );
                      
          
        }
    });
},
eventRender: function (event, element) {
  // code here
},
// other events follows.....
});

从这个 ajax 调用并根据我获得该特定日期的动态工作时间并尝试将其设置为

response.timings.start
response.timings.end

但是使用这些选项,然后在任何其他日子更改/前往,不会获取事件!基本上,它会在一个循环中无限地调用相同的函数。

尝试了很多选择,但没有运气。任何帮助/指南将不胜感激。谢谢。

4

3 回答 3

2

从 2.9.0 版开始,FullCalendar 支持动态设置选项

你应该能够做这样的事情:

$('#calendar').fullCalendar('option', 'minTime', response.timings.start);

我看过其他 SO 帖子,人们尝试按照您的方式设置选项,有些人说它有效,而另一些人说它没有。

请求此功能的GitHub问题。

实现此功能的GitHub问题。

于 2016-07-22T14:17:16.527 回答
0

在声明 fullcalendar 后尝试以下操作。

arrayOfBusinessHours 类似于

[
  {
    "dow": [1],
    "start": "09:00",
    "end": "21:30"
  },
  {
    "dow": [2],
    "start": "09:00",
    "end": "21:30"
  },
  {
    "dow": [3],
    "start": "09:00",
    "end": "21:30"
  },
  {
    "dow": [4],
    "start": "09:00",
    "end": "21:30"
  }
]

var MinTime = function (){
    var curStartTime; 
    if (arrayOfBusinessHours != undefined &&  !jQuery.isEmptyObject( arrayOfBusinessHours ) ){

        $.map(arrayOfBusinessHours, function(key, value){

            var dayOfWeek = ['sun', 'mon', 'thu', 'wed', 'tue', 'fri', 'sat'];
            var curView = calendar.fullCalendar('getView');
            // console.log(curView);
            var cdViewDay = curView.start._d;
            day = $.trim(cdViewDay).split(" ")[0];//takeout day in _d
            for(var i in key){
                if(value = day){
                    curStartTime = key[i].start;
                }
            }
        })
    }
    else{
        console.log('curDay is empty: ' +arrayOfBusinessHours);
    }
    return curStartTime;
};
var MaxTime = function (){
    var curEndTime; 
    if (arrayOfBusinessHours != undefined &&  !jQuery.isEmptyObject( arrayOfBusinessHours ) ){

        $.map(arrayOfBusinessHours, function(key, value){   
            var dayOfWeek = ['sun', 'mon', 'thu', 'wed', 'tue', 'fri', 'sat'];
            var curView = calendar.fullCalendar('getView');
            // console.log(curView);
            var cdViewDay = curView.start._d;
            day = $.trim(cdViewDay).split(" ")[0];
            for(var i in key){
                if(value = day){
                    curEndTime = key[i].end;
                }
            }
        })
    }
    else{
        console.log('curDay is empty: ' +arrayOfBusinessHours);
    }
    return curEndTime;
};
console.log('Min Time: ' +MinTime()+' Max Time: '+MaxTime());
calendar.fullCalendar('option', 'minTime', MinTime());
calendar.fullCalendar('option', 'maxTime', MaxTime());
于 2018-04-26T14:28:36.960 回答
0

例如:

objCalendar.setOption("minTime", "10:00:00");

可能工作正常。

于 2019-07-20T01:57:53.810 回答