javascript 使用 addEventSource 时 FullCalendar v.2.2.6 'hasTime' 未定义错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28027748/
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
FullCalendar v.2.2.6 'hasTime' undefined error when using addEventSource
提问by j.grima
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
. I'm not sure what's wrong exactly.
错误仅在调用时显示addEventSource
。我不确定到底出了什么问题。
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. Using an object worked:
我知道文档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);
});
回答by PX10
You need the end time.
你需要结束时间。
try this:
试试这个:
var my_events = {
events: [
{
title: 'event 1',
start: '2015-01-04',
end: '2015-01-06',
color: 'tomato'
},
]
};
回答by Syed Ekram Uddin
I found that error mostly for wrong data structure for event(s), null data for 'start' or 'end' property or invalid date format in source data.
我发现该错误主要是由于事件的错误数据结构、“开始”或“结束”属性的空数据或源数据中的无效日期格式。
回答by nickol
addEventSource doesn't really accepts array. My advise is to iterate over cal_events_1 or cal_events_2 to have something like this after each iteration:
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'
})
回答by Judson Abraham
I'm passing my in timeand out timefrom database. I have fixed this error by specifying the in timeas startand out timeas endbecause the FullCalender.jschecks for the in time and out time with that variable also I forgot to add semicolon. for GenerateCalender function.This is my code-
我通过我的时间和退房时间从数据库中。我通过将入站时间指定为开始时间和出站时间作为结束来修复此错误,因为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
});
}