fullcalendar在删除导致浏览器挂起的多个事件时速度较慢


fullcalendar is slow when removing multiple events causing the browser to hang

我使用了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
                    }
                },
            });

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

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');
                        }
                    }
                },