How to use fullcalendar addeventsource with array?

别说谁变了你拦得住时间么 提交于 2019-12-12 13:57:45

问题


Can you please say whats wrong with this? I have a javascript function called which creates a new events array and tries to refresh fullcalendar.

var events=new Array();
var numberofevents = this.serviceVariableGetDates.getTotal();

  for (i=0;i<numberofevents;i++)
       {
       //alert("numbrr:" + i);
       var dates=this.serviceVariableGetDates.getItem(i);
       console.log(dates.getData());
       var start_date = dates.getValue("c0");
       var end_date = dates.getValue("c1");
       var event_name = dates.getValue("c2");
       //var EventEntry = [ 'title: '+ event_name, 'start: '+ start_date,'end: '+ end_date ];
       events['title'] = event_name;
       events['start'] = start_date;
       events['end'] = end_date;
       events['color'] = "blue";
       this.label1.setCaption(start_date);
       //EventArray.push(EventEntry);
       console.log(events['title']);
       }
  $('#calendar').fullCalendar('addEventSource',events);
  $('#calendar').fullCalendar('rerenderEvents');

The calendar does not refresh or show the events in the events array....Through different debug methods I am sure that the events array is populated with the correct data. The start_date is for example "1307318400000" which is in the unix timestamp format. The fullcalendar is being initialized somewhere else in the begining (when the page load) and it stays unchanged even though addeventsource and rerenderevents methods are called.


回答1:


according to the docs you need to put array of events to the addEventSource function

event must be an Event Object with a title and start at the very least.

var events=new Array();
var numberofevents = this.serviceVariableGetDates.getTotal();
    for (i=0;i<numberofevents;i++)
    {
    //alert("numbrr:" + i);
    var dates=this.serviceVariableGetDates.getItem(i);
    console.log(dates.getData());
    var start_date = dates.getValue("c0");
    var end_date = dates.getValue("c1");
    var event_name = dates.getValue("c2");
    //var EventEntry = [ 'title: '+ event_name, 'start: '+ start_date,'end: '+ end_date ];
    event = new Object();       
    event.title = event_name; // this should be string
    event.start = start_date; // this should be date object
    event.end = end_date; // this should be date object
    event.color = "blue";
    event.allDay = false;
    this.label1.setCaption(start_date);
    //EventArray.push(EventEntry);
    console.log(events['title']);
    events.push(event);
    }
$('#calendar').fullCalendar('addEventSource',events);
//$('#calendar').fullCalendar('rerenderEvents');

Hope this will help!



来源:https://stackoverflow.com/questions/6182822/how-to-use-fullcalendar-addeventsource-with-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!