![](/img/trans.png)
[英]fullcalendar “typeError: Cannot read property 'hasTime' of undefined”
[英]FullCalendar v.2.2.6 'hasTime' undefined error when using addEventSource
我目前正在尝试测试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
时才会显示错误。 我不确定究竟是什么错。
UPDATE
我知道addEventSource
和removeEventSource
的文档提到使用数组作为源,但看起来它不起作用, 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);
});
你需要结束时间。
试试这个:
var my_events = {
events: [
{
title: 'event 1',
start: '2015-01-04',
end: '2015-01-06',
color: 'tomato'
},
]
};
我发现错误主要是针对事件的错误数据结构,“start”或“end”属性的空数据或源数据中的无效日期格式。
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'
})
我正在从数据库中 抽出我的时间和时间 。 我已经通过在时间上 开始和输出时间 结束 ,因为在时间和输出时间与该变量的FullCalender.js将检查也我忘了补充分号指定固定此错误。 对于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.