我在Google表上链接了一个按钮,当用户单击该按钮时,该按钮将运行以下功能:
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()函数:
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“时,它会运行另一小部分代码(参见下面),该代码将用户选择插入到单元格中。我需要等待直到这个单元格不再是空的,然后再转到下一个函数。
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):
<!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代码:
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>端编辑
知道我怎么能做到这一点吗?谢谢!
发布于 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'))checkEmailWindow.的对话框中,进程完成后,打开sendCheck的对话框。
对于Google脚本端的send():
发自:
if(bccSend == ''){
checkEmailWindow();
sendCheck();
}至:
if(bccSend == ''){
checkEmailWindow();
// sendCheck(); // Removed
}HTML和Javascript方面:
发自:
<input type="button" value="Submit" onclick="google.script.run.withSuccessHandler(google.script.host.close).form_data(document.getElementById('myform'))"/>至:
<input type="button" value="Submit" onclick="google.script.run.withSuccessHandler(google.script.run.sendCheck).form_data(document.getElementById('myform'))"/>sendCheck与withSuccessHandler.一起运行
https://stackoverflow.com/questions/61903755
复制相似问题