【问题标题】:Want to alert on html from code of .gs file想要从 .gs 文件的代码中提醒 html
【发布时间】:2021-02-25 17:24:57
【问题描述】:

我有一个 Google 表格、wep 应用程序 - 表单并想检查输入数据的重复。

如果是重复的,在将数据发送到 Google Sheet 之前,在 html 页面上弹出警报。

但是,[Google Apps 脚本的.gs 文件] 中的alert() 似乎不起作用。

我想在 [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;
  }
}

【问题讨论】:

  • 欢迎来到Stack Overflow。另一方面,代码不包含alert() 函数,不清楚“Google Sheet,wep app - form”是什么意思。请添加minimal reproducible example
  • 我会考虑检查addItem() 中的重复项,如果发现返回消息到withSuccessHandler(),消息可以告诉用户天气是否重复。
  • 嗨!您能否也分享一个您的 HTML 文件样本没有敏感数据?获得警报的一种方法是在 HTML 文件中使用 script 标记,该标记从 .gs 文件中的触发器侦听。当您的 Apps 脚本文件中的条件匹配时,您的 HTML 中的脚本将检测满足的条件,并可以从您的 HTML 文件中触发alert()。谢谢 ! :D

标签: javascript html google-apps-script web-applications


【解决方案1】:
codeList.indexOf(userInfo.studentname); //the code that user input is a number

如果userInfo.studentname 属于Number 类型,则indexOf 的严格检查将失败,因为codeListString 类型的数组。

试试

var position = codeList.indexOf(userInfo.studentname.toString());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-12
    • 2016-11-17
    • 1970-01-01
    • 2018-01-21
    相关资源
    最近更新 更多