Javascript 完整日历v.2.2.6';黑斯廷姆';使用addEventSource时出现未定义的错误

Javascript 完整日历v.2.2.6';黑斯廷姆';使用addEventSource时出现未定义的错误,javascript,jquery,fullcalendar,Javascript,Jquery,Fullcalendar,我目前正在尝试测试FullCalendar(版本2.2.6)addEventSource $('button').click(function() { $("#calendar").fullCalendar('removeEventSource', cal_events_1); $("#calendar").fullCalendar('addEventSource', cal_events_2); }); 但我总是犯这样的错误: Uncaught TypeError: Cann

我目前正在尝试测试
FullCalendar
(版本2.2.6)
addEventSource

$('button').click(function() {
    $("#calendar").fullCalendar('removeEventSource', cal_events_1);
    $("#calendar").fullCalendar('addEventSource', cal_events_2);
});
但我总是犯这样的错误:

Uncaught TypeError: Cannot read property 'hasTime' of undefined
这两个源都是硬编码的,使用其中一个源加载日历会成功加载事件,因此没有日期不正确

var cal_events_1 = [
{
  events: [
  {
      title: 'event 1',
      start: '2015-01-04',
      color: 'tomato'
  },
  {
      title: 'event 2',
      start: '2015-01-09'
  }],
  color: '#55B2DA',
  textColor: '#3c3c3c'
},
{
  events: [
  {
      title: 'event 3',
      start: '2015-01-06'
  },
  {
      title: 'event 4',
      start: '2015-01-07'
  }],
  color: 'rgb(255, 162, 71)',
  textColor: '#3c3c3c'
},
{
    events: [
    {
        title: 'event 5',
        start: '2015-01-09'
    },
    {
        title: 'event 6',
        start: '2015-01-12'
    }],
    color: 'rgb(91, 228, 118)',
    textColor: '#3c3c3c'
}];

var cal_events_2 = [
{
  events: [
  {
      title: 'event 1',
      start: '2015-01-04',
      color: 'tomato'
  },
  {
      title: 'event 2',
      start: '2015-01-09'
  },
  {
      title: 'event 3',
      start: '2015-01-09'
  }],
  color: '#55B2DA',
  textColor: '#3c3c3c'
},
{
    events: [
    {
        title: 'event 4',
        start: '2015-01-09'
    },
    {
        title: 'event 5',
        start: '2015-01-12'
    }],
    color: 'rgb(91, 228, 118)',
    textColor: '#3c3c3c'
}];
正在加载日历:

$("#calendar").fullCalendar({
    eventSources:  cal_events_1 // or cal_events_2
});
只有在调用
addEventSource
时才会显示错误。我不确定到底出了什么问题

更新

我知道并提到使用数组作为源的文档,但它似乎不起作用,
cal\u events\u 1
cal\u events\u 2
都是一个对象数组。使用工作对象:

var my_events = {
  events: [
    {
      title: 'event 1',
      start: '2015-01-04',
      color: 'tomato'
    },
    {
      title: 'event 2',
      start: '2015-01-09'
    },
    {
      title: 'event 3',
      start: '2015-01-09'
    }
  ],
  color: '#55B2DA',
  textColor: '#3c3c3c'
};

$('button').click(function() {
    $("#calendar").fullCalendar('removeEvents');
    $("#calendar").fullCalendar('addEventSource', my_events);
});
你需要结束时间

试试这个:

var my_events = {
  events: [
    {
      title: 'event 1',
      start: '2015-01-04',
      end: '2015-01-06',
      color: 'tomato'
    },
  ]
};

我发现错误主要是因为事件的数据结构错误、“开始”或“结束”属性的数据为空,或者源数据中的日期格式无效。

addEventSource实际上不接受数组。我的建议是迭代cal_events_1或cal_events_2,以便在每次迭代后都有类似的内容:

$('#calendar').fullCalendar('addEventSource', {
    events: [
    {
        title: 'event 5',
        start: '2015-01-09'
    },
    {
        title: 'event 6',
        start: '2015-01-12'
    }],
    color: 'rgb(91, 228, 118)',
    textColor: '#3c3c3c'
})

我正在通过数据库中的时间超时。我已通过将in time指定为start并将out time指定为end修复了此错误,因为FullCalender.js使用该变量检查in time和out time,我还忘了添加分号。 用于生成贷方函数。这是我的代码-

var event_array = [];

                    var selectedEvent = null;
                    FetchEventAndRenderCalendar();
                    function FetchEventAndRenderCalendar() {
                        events = [];
                        $.ajax({
                            url: "/Home/GetEvents",
                            data: "",
                            type: "GET",
                            dataType: "json",
                            async: false,
                            cache: false,
                            success: function (data) {
                                alert("success");

                                $.each(data, function (i, v) {
                                    event_array.push({
                                        userid: v.UserId,
                                        start: moment(v.LoginTime),
                                        //end: moment(v.LogoutTime)

                                        //start: moment(v.start),
                                        end: v.LogoutTime != null ? moment(v.LogoutTime) : null
                                        //color: v.themecolor,
                                        //allday: v.isfullday
                                    });

                                })

                                GenerateCalender(event_array);
                            },
                            error: function (error) {
                                alert('failed');
                            }
                        })
                    }
 function GenerateCalender(event_array) {
 $('#calender').fullCalendar({

                            events: event_array

                        });
}