删除导致浏览器挂起的多个事件时,fullcalendar很慢

时间:2016-05-10 13:16:41

标签: javascript php jquery fullcalendar

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

            });

1 个答案:

答案 0 :(得分:0)

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

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