javascript - 想要从 .gs 文件的代码中提醒 html
问题描述
我有一个 Google 表格、wep 应用程序 - 表单并想检查输入数据的重复项。
如果是重复的,请在将数据发送到 Google 表格之前在 html 页面上弹出警报。
但是,alert()
从 [.gs 文件的 Google Apps 脚本] 似乎不起作用。
我想在 [if (position >-1) ] 为真时发出警报。
我错过了什么?帮我...
function addItem(userInfo) {
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName('Sheet1');
var data = ws.getRange(2, 4, ws.getLastRow(), 1).getValues();
var codeList = data.map(function(r) {
return r[0].toString();
});
var position = codeList.indexOf(userInfo.studentname); //the code that user input is a number
if (position > -1) {
var m1 = userInfo.studentname;
sendTelegram('"' + m1 + 'no' + '"');
return true;
} else {
ws.appendRow([
userInfo.bzpatteacher,
userInfo.bzperiod,
userInfo.seatnum,
userInfo.studentname,
userInfo.reginm,
new Date(),
]);
return false;
}
}
解决方案
codeList.indexOf(userInfo.studentname); //the code that user input is a number
如果userInfo.studentname
是Number
类型,那么严格检查indexOf
将失败,因为codeList
是String
类型数组。
尝试
var position = codeList.indexOf(userInfo.studentname.toString());
推荐阅读
- android - facebook 广告给 java.lang.NullPointerException
- c# - 将对象转换为具有指定区域性的字符串
- sapui5 - SAPUI5 mockserver.js 启动多个服务器
- sql - SQL Server - 基于第三列值的行到列
- applescript - 将字符串中的数字加一
- c# - 在 Asp.Net MVC 上定位身份错误
- reactjs - 组件不会更改数组中每个元素的状态
- python - Google AppEngine Python 柔性环境上的 Catboost
- r - R:如何在同一个pdf中打印纵向和横向的图
- ios - 嵌入式 UIController 高度约束可以超越嵌入吗?