javascript FullCalendar 重新渲染事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13619053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 19:18:32  来源:igfitidea点击:

FullCalendar Re-Render Events

javascriptjqueryjquery-mobilefullcalendar

提问by Jay Mayu

I'm using Fullcalendar integrated with jQuery Mobile. When I tried to add new eventsdynamically using following method during pageshowevent it causes a JavaScript exeption as below

我正在使用与 jQuery Mobile 集成的 Fullcalendar。当我尝试在事件期间使用以下方法动态添加新事件时,pageshow它会导致 JavaScript 异常,如下所示

Uncaught TypeError: Cannot call method 'empty' of undefined

My JavaScript Code

我的 JavaScript 代码

    $('#myCalendar').live('pageshow',function(event){
            Newevents = [
                    {
                        title  : 'event1',
                        start  : '2012-11-24 01:00',
                        color:'red'

                    },
                    {
                        title  : 'event2',
                        start  : '2012-11-25',
                        end    : '2012-11-27'
                    },
                    {
                        title  : 'event3',
                        start  : '2012-11-28 12:30:00',
                        allDay : false // will make the time show
                    },
                    {
                        title  : 'event4',
                        start  : '2012-11-29 01:30:00',
                        allDay : false // will make the time show
                    }
                ];
        $('#calendar').fullCalendar('renderEvent',Newevents);
        $('#calendar').fullCalendar('rerenderEvents'); 

    });

$('#myCalendar').live('pagecreate',function(event){


    $('#calendar').fullCalendar({
            // put your options and callbacks here
            header: {
                    left:   '',
                    center: '',
                    right:  ''
                    },
            firstDay :1,
            viewDisplay: function(view) {
                $('#calendarLabel').html(view.title);
            },
             events:[
                {
                    title  : 'event1',
                    start  : '2012-11-21 01:00',
                    end:'2012-11-24 02:00',
                    color:'red'

                },
                {
                    title  : 'event2',
                    start  : '2012-11-05',
                    end    : '2012-11-07'
                },
                {
                    title  : 'event3',
                    start  : '2012-11-09 12:30:00',
                    allDay : false // will make the time show
                },
                {
                    title  : 'event4',
                    start  : '2012-11-09 01:30:00',
                    allDay : false // will make the time show
                }
            ],
            eventClick: function(calEvent, jsEvent, view) {
                alert('Event: ' + calEvent.title);
            },
            dayClick: myDayClick,
            height: 999999999
           });



});

回答by jthiesse

Rather than

而不是

.fullcalendar( 'renderEvent', []);

and

.fullCalendar( 'rerenderEvents'); 

Have you tried ... ?

你有没有尝试过 ... ?

.fullCalendar( 'addEventSource', NewEvents );

回答by Oliver Cape

For FullCalendar Version 4+

对于 FullCalendar 版本 4+

according to their documentation - https://fullcalendar.io/docs/Calendar-rerenderEvents

根据他们的文档 - https://fullcalendar.io/docs/Calendar-rerenderEvents

calendar.rerenderEvents()