[英]Running Google Script Function in HTML JavaScript Header section
I have a function that is defined in my Google App Script (code.gs) called myFunction() which accesses information from a Google Sheet.我在我的 Google App Script (code.gs) 中定义了一个名为 myFunction() 的函数,它从 Google Sheet 访问信息。 I want to be able to call this function from the script header in the html file where a HTML form is generated.
我希望能够从生成 HTML 表单的 html 文件中的脚本头调用此函数。 I have tried running google.script.run.myFunction() in the script header of the HTML page however it doesn't return any variable, just undefined.
我尝试在 HTML 页面的脚本标题中运行 google.script.run.myFunction() 但是它不返回任何变量,只是未定义。 A code snippet for the header of the HTML is below.
HTML 标题的代码片段如下。
<script>
function getArray(){
var equipment = google.script.run.myFunction();
console.log(equipment);
}
</script>
When looking at the console.log the output is undefined.查看 console.log 时,输出未定义。 I have tried changing the output of myFunction to many other types of outputs and when I use the Logger.log function in the GS, it outputs the correct variable however it simply doesn't transfer over to the HTML form.
我曾尝试将 myFunction 的输出更改为许多其他类型的输出,当我在 GS 中使用 Logger.log 函数时,它会输出正确的变量,但它根本不会转移到 HTML 表单。 Does anyone have any suggestions?
有没有人有什么建议?
I am doing it in this way as I am using this variable to dynamically created checkboxes in the HTML form and this is the simplest way I can think of doing this.我这样做是因为我使用这个变量在 HTML 表单中动态创建复选框,这是我能想到的最简单的方法。
Thanks!谢谢!
The only way to receive a return value is with the:接收返回值的唯一方法是:
.withSuccessHandler(myHandlerFunction)
The complete code would be:完整的代码将是:
<script>
function getArray(){
google.script.run
.withSuccessHandler(myHandlerFunction)
.myFunction();
}
function myHandlerFunction(equipment) {
console.log('equipment: ' + equipment);
};
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.