我有两个带有事件的日历,我想一次获得两个事件,并按照排序的日期和时间(以天为单位)显示
我已经在使用此JavaScript方法显示一个日历,现在我有两个日历,因此我想合并并显示:
calendar1= "https://www.googleapis.com/calendar/v3/calendars/<?php echo $cal_id1; ?>/events?key=<?php echo $apikey1; ?>";
calendar2= "https://www.googleapis.com/calendar/v3/calendars/<?php echo $cal_id2; ?>/events?key=<?php echo $apikey2; ?>";
formatGoogleCalendar.init({
calendarUrl:calendar1,calendar2,
past: false,
upcoming: true,
pastTopN: 5,
upcomingTopN: 7,
itemsTagName: 'li',
upcomingSelector: '#events-upcoming',
pastSelector: '#events-past',
upcomingHeading: '<div id="myDIV" class="header"><font style="float:left;"> '+digitdt+' </font><h2 style="margin:5px">Upcoming To Do List<font style="float:right; font-family:Digital-7; font-size:28pt;"> Time '+digitxt+'</font></h2></div>',
pastHeading: '',
format: ['<font style="color:#f44336; font-weight: bold; font-size: 28pt;">☞</font> <strong>', '*date*', '</strong>:<br> ', '*summary*', ' — ', '*description*', ' in ', '*location*']
});
我可以传递2个日历URL并使其显示如下吗? calendarUrl:calendar1,calendar2, 请帮忙。 谢谢。
答案 0 :(得分:0)
最后,我找到了一种解决方案,可以以简单的方式合并多个日历,并根据日期/时间在一个视图中获取所有事件。以下是我使用的代码。
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="FormatGoogleCalendar-master/dist/format-google-calendar.js"></script>
<!-- FormatGoogleCalendar Javascript file -->
<script src="FormatGoogleCalendar-master/dist/format-google-calendar.min.js"></script>
<script>
//declare calendar urls with calendar id and api key
var calender1 = "https://www.googleapis.com/calendar/v3/calendars/$cal_id/events?key=$apikey";
var calender2 = "https://www.googleapis.com/calendar/v3/calendars/$cal_id/events?key=$apikey";
//store the calendar urls in an array
var cals = [calender1,calender2];
var CAL_ID ="";
//loop through and get each calendar urls
for (j = 0; j < cals.length; j++) {
CAL_ID = cals[j];
formatGoogleCalendar.init({
calendarUrl:CAL_ID,
past: false,
upcoming: true,
pastTopN: 0,
upcomingTopN: 10,
itemsTagName: 'li',
upcomingSelector: '#events-upcoming',
pastSelector: '#events-past',
upcomingHeading: 'Upcoming Events',
pastHeading: '',
format: ['<font style="color:#f44336; font-weight: bold; font-size: 28pt;">☞</font> <strong>', '*date*', '</strong>:<br> ', '*summary*', ' — ', '*description*', ' in ', '*location*']
});
}
</script>
希望这对其他人也有帮助。