繁体   English   中英

Google.Script.Run - 不以第二种形式初始化

[英]Google.Script.Run - Not Initializing in Second Form

我正在尝试为 Google Sheet 编写一个容器绑定项目。 这将允许我在一列中搜索匹配值,并根据响应指示记录已满,允许我填写缺失值,或者,如果该值根本不存在,则写一个新的排。

实际的 HTML 不是问题,多亏了 Stackdriver Logger,我知道初始表单值被正确传递,包括将值设置为缓存,用于确定侧边栏的第二个 HTML 表单是什么。 问题是,当我提交第二个 forms,function 中的任何一个时,我试图调用以将值添加到表中没有初始化,即使脚本应该相同。

作为参考,这是初始 HTML 文件中<script>标记的内容:

document.querySelector("#cunyID").addEventListener("submit", 
      function(e) {
        e.preventDefault();
        google.script.run.cunyIDQuery(this);
        google.script.run.newSidebar();  
      }
      );

这是第二个 forms 之一中<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();  
      }
      );

这是来自第二级forms的第二个:

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 没有报告 function 打开,并且 google.script.host.close() 运行正常。 有谁知道可能会发生什么?

在 script.run 完成执行之前,脚本很可能正在关闭。

您应该使用 withSuccessHandler 回调在脚本完成时运行关闭。

    google.script.withSuccessHandler(function() {
       google.script.host.close();
    }).run.yesCUNYIDSubmit(this);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM