繁体   English   中英

删除导致浏览器挂起的多个事件时,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
                    }
                },

            });

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM