【发布时间】:2017-03-06 22:47:32
【问题描述】:
我有一个完美运行的 fullCalendar,可以在日历上显示休假时间(通过我的 ColdFusion .cfc)
<html>
<head>
<link rel="stylesheet" href="../fullcalendar-3.1.0/fullcalendar.min.css" />
<script src="../fullcalendar-3.1.0/lib/jquery.min.js"></script>
<script src="../fullcalendar-3.1.0/lib/moment.min.js"></script>
<script src="../fullcalendar-3.1.0/fullcalendar.min.js"></script>
<script src="../fullcalendar-3.1.0/gcal.js"></script>
<script>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Event Title:');
if (title) {
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
calendar.fullCalendar('unselect');
},
editable: true,
googleCalendarApiKey:'my_api_key',
url: 'https://www.googleapis.com/calendar/v3/calendars/usa__en%40holiday.calendar.google.com/events?key=my_api_key',
events: "getLeaveRequests_byDept.cfc?method=getMyData",
timeFormat: ' ', // uppercase H for 24-hour clock
eventDrop: function(event, delta) {
alert(event.title + ' was moved ' + delta + ' days\n' +
'(should probably update your database)');
}
});
});
</script>
<title>Calendar</title></head>
<body>
<div id='calendar'>
</div>
</body>
</html>
如您所见,我添加了以下内容:gcal.js 文件(谷歌日历 javascript)和以下两行尝试添加假期以及我的其他日期:
googleCalendarApiKey:'my_api_key',
url: 'https://www.googleapis.com/calendar/v3/calendars/usa__en%40holiday.calendar.google.com/events?key=my_api_key',
我的日期仍然显示正常,但日历上没有显示节假日?有什么想法吗?
这是我尝试使用“eventSources”而不是“events”
<html>
<head>
<link rel="stylesheet" href="../fullcalendar-3.1.0/fullcalendar.min.css" />
<script src="../fullcalendar-3.1.0/lib/jquery.min.js"></script>
<script src="../fullcalendar-3.1.0/lib/moment.min.js"></script>
<script src="../fullcalendar-3.1.0/fullcalendar.min.js"></script>
<script src="../fullcalendar-3.1.0/gcal.js"></script>
<script>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Event Title:');
if (title) {
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
calendar.fullCalendar('unselect');
},
editable: true,
googleCalendarApiKey: 'my_api_key',
eventSources: [
{
"getLeaveRequests_byDept.cfc?method=getMyData"
},
{
googleCalendarId: 'efgh5678@group.calendar.google.com'
}
]
});
});
</script>
<title>Calendar</title></head>
<body>
<div id='calendar'>
</div>
</body>
</html>
这是最终的有效代码:
<html>
<head>
<link rel="stylesheet" href="../fullcalendar-3.1.0/fullcalendar.min.css" />
<script src="../fullcalendar-3.1.0/lib/jquery.min.js"></script>
<script src="../fullcalendar-3.1.0/lib/moment.min.js"></script>
<script src="../fullcalendar-3.1.0/fullcalendar.min.js"></script>
<script src="../fullcalendar-3.1.0/gcal.js"></script>
<script>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Event Title:');
if (title) {
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
calendar.fullCalendar('unselect');
},
editable: true,
nextDayThreshold:'00:00:00',
// display Leave Requests plus Holidays from Google calendar
googleCalendarApiKey: '* my api key *',
eventSources: [ 'getLeaveRequests.cfc?method=getMyData', 'en.usa#holiday@group.v.calendar.google.com' ],
timeFormat: ' ', // uppercase H for 24-hour clock
eventDrop: function(event, delta) {
alert(event.title + ' was moved ' + delta + ' days\n' +
'(should probably update your database)');
}
});
});
</script>
<title>Calendar</title></head>
<body>
<div id='calendar'>
</div>
</body>
</html>
我必须添加 gcal.js,添加我的 google api 密钥,将“events”更改为“eventSources”,并使用“[]”括号而不是“{}”
【问题讨论】:
-
此答案可能有助于稍后添加源stackoverflow.com/a/35442698/5360631 和/或尝试 eventSources: { 'getLeaveRequests_byDept.cfc?method=getMyData', 'en.usa#holiday@group.v .calendar.google.com' } 与 事件 fullcalendar.io/docs/event_data/eventSources