问题描述
我目前正在做一个小项目,我想通过谷歌日历 API 检查房间是否繁忙。 为此,我使用此功能:
//checking for change of all values. Then console.log values on change and executing request if busy.
function avalabilityCheck() {
[...inputs].forEach(input => {
input.addEventListener('change',function () {
if (date.value !== "" && startTime.value !== "" && endTime.value !== ""
) {let isBusy = true;
//looping through all rooms in compartment
for (let key in comp_1) {
if (comp_1.hasOwnProperty(key)) {
let calendarID = comp_1[key];
let roomName = key;
//console.log(value);
//user input that goes into the freebusy query
let requestBody = {
timeMin: date.value + "T" + startTime.value + ":00.000Z",timeMax: date.value + "T" + endTime.value + ":00.000Z",items: [
{
id: calendarID
}
],timeZone: "GMT+01:00"
};
//make request to gcalendar if rooms are free. Giving back array on what times room is busy.
var freeRequest = gapi.client.calendar.freebusy.query(requestBody);
//executing request.
freeRequest.execute(function (resp) {
var responSEObject = JSON.stringify(resp);
console.log(responSEObject);
if (resp.calendars[calendarID].busy.length < 1) {
console.log(`${roomName} is free`);
} else { isBusy = false;
console.log("room is Busy");}
})
}
}
console.log("finito");
if (isBusy === false) {
console.log("working?");
}
else{console.log("not working");}
} else {
console.log("change date pls");
}
}
)
}
)
}
现在let isBusy = true;
,当房间很忙时,我希望 isBusy 为假:
if (resp.calendars[calendarID].busy.length < 1) {
console.log(`${roomName} is free`);
} else { isBusy = false;
console.log("room is Busy");}
所以当我运行应用程序时,控制台应该给出:
console.log("finito");
if (isBusy === false) {
console.log("working?");
}
else{console.log("not working");}
但它只向控制台提供“finito”,显然没有检查 isBusy 的状态。 有没有人看到这里的问题是什么? 谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)