javascript - Google.Script.Run - 不以第二种形式初始化
问题描述
我正在尝试为 Google 表格编写一个容器绑定项目。这将允许我在一列中搜索匹配值,并根据响应指示记录已满,允许我填写缺失值,或者,如果该值根本不存在,则写一个新的排。
实际的 HTML 不是问题,感谢 Stackdriver Logger,我知道初始表单值被正确传递,包括将值设置为缓存,用于决定侧边栏的第二个 HTML 表单是什么。问题是,当我提交第二种形式中的任何一种时,我试图调用以将值添加到表中的函数没有初始化,即使脚本应该是相同的。
作为参考,这是<script>
初始 HTML 文件中标记的内容:
document.querySelector("#cunyID").addEventListener("submit",
function(e) {
e.preventDefault();
google.script.run.cunyIDQuery(this);
google.script.run.newSidebar();
}
);
这是<script>
第二种形式之一的内容:
gpa.onchange = function setTwoNumberDecimal(event) {
this.value = parseFloat(this.value).toFixed(2);
};
q1.onchange = function setWholeNumber(event) {
this.value = parseFloat(this.value).toFixed(0);
};
q2.onchange = function setWholeNumber(event) {
this.value = parseFloat(this.value).toFixed(0);
};
q3.onchange = function setWholeNumber(event) {
this.value = parseFloat(this.value).toFixed(0);
};
document.querySelector("#noCUNYID").addEventListener("submit",
function(e) {
e.preventDefault();
google.script.run.noCUNYIDSubmit(this);
google.script.host.close();
}
);
这是来自第二级形式的第二个:
q1.onchange = function setWholeNumber(event) {
this.value = parseFloat(this.value).toFixed(0);
};
q2.onchange = function setWholeNumber(event) {
this.value = parseFloat(this.value).toFixed(0);
};
q3.onchange = function setWholeNumber(event) {
this.value = parseFloat(this.value).toFixed(0);
};
document.querySelector("#yesCUNYID").addEventListener("submit",
function(e) {
e.preventDefault();
google.script.run.yesCUNYIDSubmit(this);
google.script.host.close();
}
);
尽管理论上 google.script.run 应该调用函数,但 Stackdriver 没有报告函数打开,并且 google.script.host.close() 运行正常。有谁知道可能会发生什么?
解决方案
在 script.run 完成执行之前,脚本很可能正在关闭。
您应该使用 withSuccessHandler 回调在脚本完成时运行关闭。
google.script.withSuccessHandler(function() {
google.script.host.close();
}).run.yesCUNYIDSubmit(this);
推荐阅读
- python - 如何在无服务器框架中将外部 python 模块导入 AWS Lambda 函数?
- julia - 参数类型构造函数中“where”关键字的用途
- html - 强制本地 html 文件中的超链接打开关联的应用程序而不是下载
- python - 通过 CustomJS 更新轴范围时,分类轴上的矩形字形表现异常 - Bokeh
- php - 获取多维数组的值
- reactjs - 如何在 ReactJS 中通过上下文提供函数?
- html - 复选框按钮看起来很奇怪的移动视图
- java - 在Android上读取jpeg文件的量化表
- c++ - Libharu 解释 QT c++ 中的链接
- gitlab - 有没有办法在 gitlab UI 中指定环境变量并为每个环境定义一个值?