Javascript 无法读取属性';事件';未定义的(谷歌日历API)
大多数情况下,代码运行正常,但有时会出现以下错误: 未捕获类型错误:无法读取未定义的属性“事件” 列表中的事件((索引):110) 这是我的密码:Javascript 无法读取属性';事件';未定义的(谷歌日历API),javascript,php,google-calendar-api,Javascript,Php,Google Calendar Api,大多数情况下,代码运行正常,但有时会出现以下错误: 未捕获类型错误:无法读取未定义的属性“事件” 列表中的事件((索引):110) 这是我的密码: function listUpcomingEvents() { var request = gapi.client.calendar.events.list({ //Here's where the error comes from ((index):110) 'calendarId': 'XXXX', 'timeMi
function listUpcomingEvents() {
var request = gapi.client.calendar.events.list({ //Here's where the error comes from ((index):110)
'calendarId': 'XXXX',
'timeMin': (new Date()).toISOString(),
'showDeleted': false,
'singleEvents': true,
'maxResults': 5,
'orderBy': 'startTime',
'timeMax':(new Date(tomorrow)).toISOString(),
});
request.execute(function(resp) {
var events = resp.items;
FsalA('');
if (events.length > 0) {
for (i = 0; i < events.length; i++) {
var event = events[i];
var when = event.start.dateTime;
if (!when) {
when = event.start.date;
}
var when2 = event.end.dateTime;
if (!when2) {
when2 = event.end.date;
}
if(!event.summary) {
event.summary = 'Opptatt'
}
var d = new Date(when);
var time = d.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit', hour12: false});
var d = new Date(when2);
var time2 = d.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit', hour12: false});
var startTime = time.replace('.', ':')
var endTime = time2.replace('.', ':')
FsalA('(' + startTime + ' - ' + endTime + ') ' + event.summary + '\n')
}
} else {
FsalA('Ingen møter');
}
});
}
在那之后我有
<?php
include './static/js/FTA.php';
include './static/js/FTB.php';
include './static/js/GRN.php';
include './static/js/KLB.php';
include './static/js/KOB.php';
include './static/js/KVA.php';
include './static/js/SAN.php';
include './static/js/SKI.php';
include './static/js/SV1.php';
include './static/js/SV2.php';
include './static/js/THU.php';
include './static/js/TRO.php';
?>
这会触发给出错误的代码。在我的例子中,这与您的问题类似:
gapi.client.init({…googleClientConfig}){
gapi.client.calendar.events.list({…calendarRequestParams}){
让事件=response.result.items;
/*对事件做点什么*/
});
});
然而,以下几点是成功的。成功的关键是额外的一行gapi.client.load('calendar','v3',…)
:
gapi.client.init({…googleClientConfig})。然后(()=>{
gapi.client.load('calendar','v3',()=>{
gapi.client.calendar.events.list({…calendarRequestParams}){
让事件=response.result.items;
/*对事件做点什么*/
});
});
});
在没有代码的情况下按照中的设置进行操作。如果工作正常,请一点一点地添加您自己的代码。你可能留下了一些悬而未决的代码。
<?php
include './static/js/FTA.php';
include './static/js/FTB.php';
include './static/js/GRN.php';
include './static/js/KLB.php';
include './static/js/KOB.php';
include './static/js/KVA.php';
include './static/js/SAN.php';
include './static/js/SKI.php';
include './static/js/SV1.php';
include './static/js/SV2.php';
include './static/js/THU.php';
include './static/js/TRO.php';
?>