weixin_33747129 2016-03-17 09:22 采纳率: 0%
浏览 77

Fullcalendar minTime ajax

I'm trying to change the minTime in fullcalendar according to the database schedule through an ajax request on the viewRender, but it goes into a loop.

Part of my calendarOptions:

var calendarOptions = {
    header: {
        left: ' today',
        center: 'prev,title,next',
        right: 'agendaWeek,resourceDay'
    },
    defaultView: 'resourceDay',

The viewRender:

viewRender: function(view, element){
        var curDate = ($('#calendar').fullCalendar('getDate')).format('d-DD-MM').split('-');
        var curWeekDay = curDate[0];
        var curMonthDay = curDate[1];
        var curMonth = curDate[2];

        $.ajax({
            url: 'calendar/getBusinessHours',
            type: 'GET',
            data: {
                'day': curWeekDay,
                "_token": $('body').find( 'input[name=_token]' ).val()
            },
            success: function (response) {
                $('#calendar').fullCalendar("destroy");
                $("#calendar").fullCalendar(
                    $.extend(calendarOptions, {
                        defaultDate: currentDate,
                        minTime: response[0].open_time+':00',
                        maxTime: response[0].close_time+':00'
                    })
                );
            }
        });
    },

The ajax response is '08:00:00' so there is no problem there;

  • 写回答

1条回答 默认 最新

  • ?yb? 2016-03-18 08:40
    关注

    I have not tested this but I believe your problem comes from destroying fullCalendar and setting it up again. Essentially, what happens is that your calendar loads and the view is rendered, then you make an ajax request, destroy the calendar, create a new one which triggers viewRender again and so on.

    success: function (response) {
                $('#calendar').fullCalendar("destroy");
                $("#calendar").fullCalendar(...
    

    You can either load the minTime and maxTime before initializing the calendar (getting the values from the database with an ajax call and initializing the calendar only when the values are retrieved from the back-end so you can pass them to the initialization as options) or change their values inside a different event (not viewRender)

    What you can also do is add a variable to the equation and launch the AJAX conditionally - if the calendar is not in a process of reconstructing itself with the new minTime and maxTime.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。