javascript - 关闭谷歌应用脚本中的modalDialogue框后运行代码
问题描述
在单击 ID 为“submitButton”的按钮后,我试图关闭模态对话框并在函数对象中运行代码。
var FuncObj = {
checker:checker
checker2:checker2
};
以下是我的 HTML
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js">.
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<style>
.padd5{
padding: 5px 0;
}
</style>
</head>
<body>
<div class="continue-button">
<button class='blue' id="submitButton">Continue </button>
</div>
</body>
<script>
$("#submitButton").click(
google.script.run.withSuccessHandler(close).runThatFunction(checker);`
function close(){
google.script.host.close();
}
</script>
</html>
下面是呈现 HTML 的代码,HTML 被正确呈现,但当我单击按钮时没有任何反应:
function test(functionName) {
if (condition1){
FuncObj[functionName]();
}
if(condition2) {
var html = HtmlService
.createTemplateFromFile('unpaid')
.evaluate()
.getContent();
var finalHtml = HtmlService.createTemplate(html).evaluate().setWidth(300).setHeight(560);
SpreadsheetApp.getUi()
.showModalDialog(finalHtml, 'test');
}
else {
SpreadsheetApp.getActive().toast("Exhausted");
}
}
这是调用该函数的代码:
function runThatFunction(functionName){ FuncObj[functionName]();}
代码顺序如下 -
- 上面的第一个“test(functionName)”将运行。
- 如果它进入条件 2,则 HTML 中的模态对话框将显示给用户
- 一旦用户单击 ID 为“submitButton”的按钮,模式对话框应该关闭并运行作为参数传递给上面“1”中的测试函数的函数。
我被困在上面序列的#2上。无法关闭 modalDialogue 框并运行它后面的任何函数。
解决方案
要在关闭后运行代码,请添加要在之后运行的代码google.script.host.close();
。请记住,这只能通过调用close()
函数完成关闭。
推荐阅读
- python - 在 AWS 上运行并行 R + Python 作业?
- github - 如何使 github 动作矩阵元素有条件
- css - 为什么高度在具有绝对 div 的 Firefox 中表现如此不同?
- php - 使用 sprintf 为 WooCommerce 支付方式费用显示不同的文本标签
- c++ - 我在哪里可以找到 Stroustrup 的《编程原理与实践》一书中的“Try This”解决方案?
- angular - 隐藏该网站是用 Angular 制作的
- c - 需要对我编写的代码的反馈,目前收到错误 CS50
- database - Oracle SQL 查询中的旧式联接
- c - 在保持文件锁定的同时切换模式
- linux - 设置用于对 XDP 负载均衡器进行基准测试的环境