0

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

Uncaught TypeError: Cannot call method 'empty' of undefined

我的 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
           });



});
4

1 回答 1

5

而不是

.fullcalendar( 'renderEvent', []);

.fullCalendar( 'rerenderEvents'); 

你有没有尝试过 ... ?

.fullCalendar( 'addEventSource', NewEvents );
于 2012-11-30T14:32:26.370 回答