![](/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.