【问题标题】:fullcalendar is slow when removing multiple events causing the browser to hang删除导致浏览器挂起的多个事件时,fullcalendar 很慢
【发布时间】:2016-05-10 13:16:41
【问题描述】:

我使用了 FullCalendar ,创建了 1500 个事件。 每个事件都与特定的用户名相关。 我创建了一个自定义按钮,当用户按下它时 - 日历假设只向他显示与他相关的事件。 这种机制实际上是有效的,但我可能做错了什么,因为当事件很少(在 ~10 个事件上测试)时它工作正常,但现在我有 1500 个事件,它挂起我的浏览器并导致它卡住.. 任何帮助都会得到帮助。

代码:

$('#calendar').fullCalendar({
                editable: false, // Disable editing events directly from GUIhed over 2 days - this is the time that the run is counted as few days run
                customButtons: {
                    myReports: { //Filter my reports
                        text: 'My Reports',
                        click: function () {
                            events_to_remove = $('#calendar').fullCalendar('clientEvents', function(event) {
                                <?php echo "var sessionUsername = \"".$username."\";\n";?>
                                return event.username != sessionUsername;
                            });
                            $('#calendar').fullCalendar( 'removeEventSource',events_to_remove);
                            $.each( events_to_remove, function( key, e ) {
                                    $('#calendar').fullCalendar( 'removeEvents',e.id);
                            });
                        }
                    },
                    allReports: { //Filter all reports
                        text: 'All Reports',
                        click: function() {
                            $('#calendar').fullCalendar( 'refetchEvents');
                        }
                    }
                },

                header: {
                    left: 'myReports allReports',
                    center: 'prev title next',
                    right: 'today agendaDay,agendaWeek,month',

                },

                //read DB
                events: {
                    url: 'modules/scheduler/scheduler_backend.php',
                    type: 'POST',
                    data: {
                        type: 'fetch',
                        start: $('calendar').fullCalendar('getView').start,
                        end: $('calendar').fullCalendar('getView').end,
                    },
                    error: function() {
                        alert('there was an error while fetching events!');
                    },

                    success: function(response){
                      //console.log(response); //For debug
                    }
                },

            });

【问题讨论】:

    标签: javascript php jquery fullcalendar


    【解决方案1】:

    找到了解决办法。使删除事件更加优雅:

    customButtons: {
                        myReports: { //Filter my reports
                            text: 'My Reports',
                            click: function () {
                                $('#calendar').fullCalendar( 'removeEvents',function(event) {
                                    <?php echo "var sessionUsername = \"".$username."\";\n";?>
                                    return event.username != sessionUsername;
                                });
                            }
                        },
                        allReports: { //Filter all reports
                            text: 'All Reports',
                            click: function() {
                                $('#calendar').fullCalendar( 'refetchEvents');
                            }
                        }
                    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-25
      • 2011-02-21
      • 2023-04-02
      • 2012-04-03
      • 1970-01-01
      • 2019-04-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多