Javascript Google脚本变量未定义

Javascript Google脚本变量未定义,javascript,Javascript,我正在code.gs中创建一个脚本,并希望在HTML页面的界面中检索变量 我无法从html页面上code.js中的函数中检索变量 代码G.gs: function doGet() { return HtmlService.createHtmlOutputFromFile('index') .setSandboxMode(HtmlService.SandboxMode.IFRAME); } function test(){ var test="hello"; return

我正在code.gs中创建一个脚本,并希望在HTML页面的界面中检索变量

我无法从html页面上code.js中的函数中检索变量

代码G.gs:

function doGet() {
  return HtmlService.createHtmlOutputFromFile('index')
        .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

function test(){
 var test="hello";
return test;
}
Index.html:

google.script.run.test();

document.writeln(test);
谢谢塔奈克

现在我正在尝试实现价值观​​从html页面中的code.gs数组

CODE.GS:

function temperature2(){
var valueTemp = new Array([],[],[]);

valueTemp[0][1] = "6"
valueTemp[0][2] = "7"
valueTemp[0][3] = "8"

valueTemp[1][1] = "32"
valueTemp[1][2] = "45"
valueTemp[1][3] = "41"


  return valueTemp;
}
data: [ 
[google.script.run.withSuccessHandler(valueTemp[0][1]).temperature2,
 google.script.run.withSuccessHandler(valueTemp[1][1]).temperature2()],
 [google.script.run.withSuccessHandler(valueTemp[0][2]).temperature2, 
google.script.run.withSuccessHandler(valueTemp[1][2]).temperature2()], 
[google.script.run.withSuccessHandler(valueTemp[0][3]).temperature2, 
google.script.run.withSuccessHandler(valueTemp[1][3]).temperature2()], 
........  ]
INDEX.html:

function temperature2(){
var valueTemp = new Array([],[],[]);

valueTemp[0][1] = "6"
valueTemp[0][2] = "7"
valueTemp[0][3] = "8"

valueTemp[1][1] = "32"
valueTemp[1][2] = "45"
valueTemp[1][3] = "41"


  return valueTemp;
}
data: [ 
[google.script.run.withSuccessHandler(valueTemp[0][1]).temperature2,
 google.script.run.withSuccessHandler(valueTemp[1][1]).temperature2()],
 [google.script.run.withSuccessHandler(valueTemp[0][2]).temperature2, 
google.script.run.withSuccessHandler(valueTemp[1][2]).temperature2()], 
[google.script.run.withSuccessHandler(valueTemp[0][3]).temperature2, 
google.script.run.withSuccessHandler(valueTemp[1][3]).temperature2()], 
........  ]

我修改代码以缩短它,使其更具可读性

,尽管我不确定这是否是您想要的结果,例如,对“Index.html”的修改如何
google.script.run.withSuccessHandler(test=>document.writeln(test)).test()