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 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python