google.script.run.myFunction()可用的变量的范围是什么 [英] What is the scope of variables available to google.script.run.myFunction()

查看:86
本文介绍了google.script.run.myFunction()可用的变量的范围是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



HtmlOutput窗口中的Javascript代码可以漂浮在Google电子表格中更改gs中的变量和调用方法首先创建HtmlOutput的代码?



我有一个浮动表单的Google电子表格:


someCode.gs




  var theForm; 
var theSpreadsheet;
函数makeForm(){

theForm = HtmlService.createTemplateFromFile('aForm')。evaluate();
theSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
theSpreadsheet.show(theForm);

}

函数recordTheForm(jsonFormData){

theForm.clear();






附加到aFormHTML中的按钮。 html我有一个函数调用回文件someCode.gs。


aForm.html




 
google.script.run.recordTheForm(jsonTheForm);

我是对的,即使它是从someCode.gs实例化的, recordTheForm()的调用者可以不知道该内存空间的内容吗?



有没有办法得到它?例如来回传递上下文?

解决方案

GAS中的变量:



浏览器按钮点击和其他浏览器事件产生对GAS的呼叫。从浏览器到GAS的每个调用都会导致您的GAS代码重新运行,重新初始化所有变量。这是全局变量的问题。全局变量需要从浏览器传递回GAS代码或从数据库或脚本属性重新加载。


I'd like a little sanity check if I may.

Can Javascript code in an HtmlOutput window floated over a Google spreadsheet alter variables and call methods in the gs code that created the HtmlOutput in the first place?

I have a Google spreadsheet with a floating form created like this:

someCode.gs

var theForm;
var theSpreadsheet;
function makeForm() {
    :
  theForm = HtmlService.createTemplateFromFile('aForm').evaluate();
  theSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();    
  theSpreadsheet.show(theForm);
    :
}

function recordTheForm(jsonFormData) {
    :
  theForm.clear();
    :
}

Attached to a button in the HTML of "aForm.html" I have a function call back into the file "someCode.gs".

aForm.html

  :
google.script.run.recordTheForm(jsonTheForm);
  :

Am I right that, even though it was instantiated from someCode.gs, the caller of recordTheForm() can have no knowledge of the contents of that originating memory space?

Is there anyway to get it? such as passing a "context" back and forth?

解决方案

Variables in GAS:

Browser button clicks and other browser events produce a call to GAS. Every call from the browser to GAS causes your GAS code to re-run, re-initializing all variables. This is a problem for global variables. Global variables need to be passed back from the Browser to your GAS code or reloaded from the Database or Script Properties.

这篇关于google.script.run.myFunction()可用的变量的范围是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆