使用addEventSource时,FullCalendar v.2.2.6'hasTime'未定义错误

j.g*_*ima 9 javascript jquery fullcalendar

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

$('button').click(function() {
    $("#calendar").fullCalendar('removeEventSource', cal_events_1);
    $("#calendar").fullCalendar('addEventSource', cal_events_2);
});
Run Code Online (Sandbox Code Playgroud)

但我总是收到这个错误:

Uncaught TypeError: Cannot read property 'hasTime' of undefined
Run Code Online (Sandbox Code Playgroud)

两个源都是硬编码的,并且加载日历时,任一源都会成功加载事件,因此没有日期不正确.

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'
}];
Run Code Online (Sandbox Code Playgroud)

加载日历:

$("#calendar").fullCalendar({
    eventSources:  cal_events_1 // or cal_events_2
});
Run Code Online (Sandbox Code Playgroud)

仅在呼叫时显示错误addEventSource.我不确定究竟是什么错.

UPDATE

我知道使用数组作为源的文档addEventSourceremoveEventSource提及,但它看起来不起作用,cal_events_1并且cal_events_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);
});
Run Code Online (Sandbox Code Playgroud)

小智 6

你需要结束时间.

试试这个:

var my_events = {
  events: [
    {
      title: 'event 1',
      start: '2015-01-04',
      end: '2015-01-06',
      color: 'tomato'
    },
  ]
};
Run Code Online (Sandbox Code Playgroud)