简体   繁体   English

如何将 fullcalendar addeventsource 与数组一起使用?

[英]How to use fullcalendar addeventsource with array?

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.我有一个 javascript function 调用它创建一个新的事件数组并尝试刷新 fullcalendar。

var events=new Array();变种事件=新数组();
var numberofevents = this.serviceVariableGetDates.getTotal(); 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. start_date 是例如“1307318400000”,它采用 unix 时间戳格式。 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. fullcalendar 在开始时(页面加载时)在其他地方被初始化,即使调用了 addeventsource 和 rerenderevents 方法,它也保持不变。

according to the docs you need to put array of events to the addEventSource function根据文档,您需要将事件数组放入 addEventSource function

event must be an Event Object with a title and start at the very least. event 必须是一个Event Object并且至少开始。

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!希望这会有所帮助!

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

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