这让我抓狂,代码昨天还可以工作,但现在不行了。我尝试再次检查所有语法,但问题仍然存在。来自 Google Sheets 的此服务器端请求显示服务器端的值(Logger.log()
),但返回null
在客户端。
function supervisorLine(lineData) {
if (lineData == 'Name Value is not VALID!') {
console.log("Supervisor Name Issue!");
} else {
document.getElementById('Team').value = lineData[7];
document.getElementById('Shift').value = lineData[12];
document.getElementById('action').classList.remove("disabled");
console.log("team " + lineData[7] + " shift " + lineData[12]);
////////////////////////////////// need to be Moved somewhere after password check!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
google.script.run.withSuccessHandler(function(quickStat2) {
console.log(quickStat2)
}).loginRecords(lineData[7], lineData[12]);
}
}
这也是我的服务器端代码:
function loginRecords(team, shift) {
var sh = ss.getSheetByName("Attn Rec");
var result = [];
var matchRec = sh.getRange("a2:l" + sh.getLastRow()).getValues().filter(function(a) {
return a[1] === shift && a[4].valueOf() == team.valueOf()
});
uniqeLogin = removeDups(matchRec.map(function(a) {
return a[9]
}));
// Logger.log(uniqeLogin);
uniqeLogin.forEach(function(a) {
var ary = [team, 0, shift, "", 0, 0, 0, 0, 0];
matchRec.forEach(function(r) {
if (r[9] === a) {
ary[1] = new Date(r[0]);
ary[3] = r[8];
switch (r[3].toString().toLowerCase()) {
case "off-site work":
case "hr action":
ary[8]++;
break;
case "present":
case "late transfer":
case "transfer":
ary[4]++;
break;
case "no show":
ary[5]++;
break;
case "Sick":
case "vacation":
ary[7]++;
break;
case "late":
case "approved delay start":
ary[6]++;
break;
}
}
});
result.push(ary);
});
Logger.log(result);
return result;
}
回顾一下,Logger.log(result)
返回我需要的数组,但是console.log(quickStat2)
回报null
.
我前段时间遇到了这个问题,它也几乎让我发疯(哦,松散类型 JavaScript 的乐趣!)。问题是你正在尝试返回一个不可接受的类型数据到客户端。通过调用函数google.script.run
对它们可以返回的内容有限制(例如,您应该避免Date
实例)。
限制类型
目前,您无法返回(请查看文档 https://developers.google.com/apps-script/guides/html/reference/run#myFunction(...)有关限制的详细说明):
-
Date
实例;
- any
Function
;
- DOM 元素(尽管
<form>
是允许的);
Solution
改变ary[1]= new Date(r[0]);
to ary[1] = r[0];
应该可以解决问题,只需移动Date
解析给客户端。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)