Fullcalendar动态设置minTime和maxTime

时间:2016-07-21 12:09:40

标签: php fullcalendar codeigniter-2 fullcalendar-scheduler

我已经实施了 fullcalendar v2资源日历。我无法解决的问题是根据日期设置动态 minTime maxTime 。每天都有不同的工作时间。

  

周一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

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

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

3 个答案:

答案 0 :(得分:2)

从版本2.9.0开始,FullCalendar支持setting options dynamically

你应该可以这样做:

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

我见过其他SO帖子,人们尝试按照你的方式设置选项,有些人说它有效,有些人则认为没有。

GitHub issue请求此功能。

实施此功能的GitHub issue

答案 1 :(得分: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());

答案 2 :(得分:0)

例如:

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

可能工作正常。