简体   繁体   English

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

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

I am trying to write a container-bound project for a Google Sheet.我正在尝试为 Google Sheet 编写一个容器绑定项目。 It would allow me to search for a matching value in one column, and depending on the response, dictate that the record is full, allow me to fill in the missing values, or, if the value is not there at all, write a new row.这将允许我在一列中搜索匹配值,并根据响应指示记录已满,允许我填写缺失值,或者,如果该值根本不存在,则写一个新的排。

The actual HTML isn't an issue, and thanks to Stackdriver Logger, I know that the initial form values are being passed correctly, including setting a value as cache, which is used to decide what is the second HTML form for the sidebar.实际的 HTML 不是问题,多亏了 Stackdriver Logger,我知道初始表单值被正确传递,包括将值设置为缓存,用于确定侧边栏的第二个 HTML 表单是什么。 The thing is that, when I submit either of the second forms, the function I'm attempting to call to add the values to the table are not initializing, even though the script should be the same.问题是,当我提交第二个 forms,function 中的任何一个时,我试图调用以将值添加到表中没有初始化,即使脚本应该相同。

For reference, this is the the contents of the <script> tags in the initial HTML file:作为参考,这是初始 HTML 文件中<script>标记的内容:

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

This is the contents of <script> in one of the second forms:这是第二个 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();  
      }
      );

And this is from the second of the second-level forms:这是来自第二级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();  
      }
      );

Even though, theoretically, google.script.run should be calling for the functions, Stackdriver is not reporting the function opening, and google.script.host.close() is running correctly.尽管理论上 google.script.run 应该调用这些函数,但 Stackdriver 没有报告 function 打开,并且 google.script.host.close() 运行正常。 Does anyone know what might be going on?有谁知道可能会发生什么?

It is likely that the script is closing before the script.run completes execution.在 script.run 完成执行之前,脚本很可能正在关闭。

You should use the withSuccessHandler callback to run close when the script is completed.您应该使用 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