首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Google脚本调用函数,该函数执行一个Modal对话框,然后在用户进行选择后再执行另一个函数

Google脚本调用函数,该函数执行一个Modal对话框,然后在用户进行选择后再执行另一个函数
EN

Stack Overflow用户
提问于 2020-05-20 01:48:32
回答 1查看 1K关注 0票数 1

我在Google表上链接了一个按钮,当用户单击该按钮时,该按钮将运行以下功能:

代码语言:javascript
运行
复制
function ModalSelection(){
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('main_gen');
  var cell = ss.getRange(1,1).getValue();
  if(cell == ''){
    checkWindow(); //It runs this function if `cell` is empty.
  //I would like to run another function here...anotherFunction()...but not until
  //the user has made their selections from the Modal Dialog box. 
  }
  else {send();} //send is not relevant to this question.
}

下面是checkWindow()函数:

代码语言:javascript
运行
复制
function checkWindow(){
  var ui = SpreadsheetApp.getUi();
  var result = emailList(); //This is a string grabbed from another function.
  //Call the HTML file and set the width and height
  var html = HtmlService.createHtmlOutput(result)
    .setWidth(400)
    .setHeight(450);

  //Display the dialog
  var dialog = ui.showModalDialog(html, "Select your choices here.");
}

当运行checkWindow()函数并选择"Submit“时,它会运行另一小部分代码(参见下面),该代码将用户选择插入到单元格中。我需要等待直到这个单元格不再是空的,然后再转到下一个函数。

代码语言:javascript
运行
复制
function form_data(e){
  SpreadsheetApp.flush();
  var value = [e.email];
  var val = value[0].toString();
  for(var i = 1; i<value.length; i++){val += ', ' + value[i];}
  SpreadsheetApp.getActiveSheet().getRange(2, 2).setValue(val);
  //I have tried adding the anotherFunction(); function right here, but the code breaks and the only error I see
  //in the console error log is "Uncaught". It gives me no additional details. 
}

编辑以包含所有HTML.

HTML代码如下(EmailCheckBox.html):

代码语言:javascript
运行
复制
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
  </head>
  <body>
    <form id='myform'>
        <table border=0>

           %email

        </table>

    </form><br>
        <input type="button" value="Submit" onclick="google.script.run.withSuccessHandler(google.script.host.close).form_data(document.getElementById('myform'))"/>
        <input type="button" value="Close" onclick="google.script.host.close()"/>
  </body>

它所指的电子邮件%是这个JS代码:

代码语言:javascript
运行
复制
function checkEmail(List){
  var output = '';
  for(var i=0; i<List.length; i++)
  {
    output += '<tr><td><input type="checkbox" name="email" id="' + List[i] + '" value="' + List[i] + '"/>'+ List[i] + '</td></tr>'; 
  }
  var result = HtmlService.createHtmlOutputFromFile('EmailCheckBox').getContent();
  result = result.replace('%email', output);
  Logger.log(result);

  return result;
}
</html>

端编辑

知道我怎么能做到这一点吗?谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-20 04:43:39

我相信你的目标如下。

checkEmailWindow.的对话框中,您希望在进程完成后打开sendCheck的对话框

为了这个,这个修改怎么样?

修改要点:

  • 在您的脚本中,checkEmailWindow()sendCheck()一直在运行。由此,checkEmailWindow()打开的对话框被sendCheck()打开的对话框覆盖。
  • 为了在checkEmailWindow对话框中打开sendCheck()对话框,我对google.script.run.withSuccessHandler(google.script.host.close).form_data(document.getElementById('myform'))做了如下修改。
    • google.script.run.withSuccessHandler(google.script.run.sendCheck).form_data(document.getElementById('myform'))
    • By --在checkEmailWindow.

的对话框中,进程完成后,打开sendCheck的对话框。

对于Google脚本端的send()

发自:

代码语言:javascript
运行
复制
if(bccSend == ''){
  checkEmailWindow();
  sendCheck();
}

至:

代码语言:javascript
运行
复制
if(bccSend == ''){
  checkEmailWindow();
  // sendCheck();  // Removed
}

HTML和Javascript方面:

发自:

代码语言:javascript
运行
复制
<input type="button" value="Submit" onclick="google.script.run.withSuccessHandler(google.script.host.close).form_data(document.getElementById('myform'))"/>

至:

代码语言:javascript
运行
复制
<input type="button" value="Submit" onclick="google.script.run.withSuccessHandler(google.script.run.sendCheck).form_data(document.getElementById('myform'))"/>

  • sendCheckwithSuccessHandler.

一起运行

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61903755

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档