简体   繁体   English

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

[英]FullCalendar v.2.2.6 'hasTime' undefined error when using addEventSource

I'm currently trying to test out FullCalendar (version 2.2.6) addEventSource 我目前正在尝试测试FullCalendar (版本2.2.6) addEventSource

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

but I'm always getting this error: 但我总是收到这个错误:

Uncaught TypeError: Cannot read property 'hasTime' of undefined

Both sources are hard coded and loading the calendar with either source loads the events successfully, so no date is incorrect. 两个源都是硬编码的,并且加载日历时,任一源都会成功加载事件,因此没有日期不正确。

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'
}];

Loading the calendar: 加载日历:

$("#calendar").fullCalendar({
    eventSources:  cal_events_1 // or cal_events_2
});

The error is displayed only when calling addEventSource . 仅在调用addEventSource时才会显示错误。 I'm not sure what's wrong exactly. 我不确定究竟是什么错。

UPDATE UPDATE

I know the documentation of addEventSource and removeEventSource mention using an array as a source but it looks like it does not work, cal_events_1 and cal_events_2 are both an array of objects. 我知道addEventSourceremoveEventSource的文档提到使用数组作为源,但看起来它不起作用, cal_events_1cal_events_2都是一个对象数组。 Using an object worked: 使用对象工作:

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);
});

You need the end time. 你需要结束时间。

try this: 试试这个:

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

我发现错误主要是针对事件的错误数据结构,“start”或“end”属性的空数据或源数据中的无效日期格式。

addEventSource doesn't really accepts array. addEventSource并不真正接受数组。 My advise is to iterate over cal_events_1 or cal_events_2 to have something like this after each iteration: 我的建议是在每次迭代后迭代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'
})

I'm passing my in time and out time from database . 我正在从数据库中 抽出的时间时间 I have fixed this error by specifying the in time as start and out time as end because the FullCalender.js checks for the in time and out time with that variable also I forgot to add semicolon . 我已经通过在时间上 开始输出时间 结束 ,因为在时间和输出时间与该变量的FullCalender.js将检查也我忘了补充分号指定固定此错误。 for GenerateCalender function.This is my code- 对于GenerateCalender函数。这是我的代码 -

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

                        });
}

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

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