javascript 如何在数组中使用 fullcalendar addeventsource?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6182822/
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-25 19:48:01  来源:igfitidea点击:

How to use fullcalendar addeventsource with array?

javascriptjqueryarraysfullcalendar

提问by Johnny Dep

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

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

var 事件=新数组();
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.

日历不会刷新或显示事件数组中的事件....通过不同的调试方法,我确信事件数组填充了正确的数据。例如,start_date 是 unix 时间戳格式的“1307318400000”。fullcalendar 在开始时(页面加载时)在其他地方初始化,即使调用 addeventsource 和 rerenderevents 方法,它也保持不变。

回答by zlosim

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

根据您需要将事件数组放入 addEventSource 函数的文档

event must be an Event Objectwith 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!

希望这会有所帮助!