google.script.run不返回字符串 [英] google.script.run not returning string
问题描述
试图弄清楚用于制作Google文档插件的Google Apps脚本. 我有:
Code.gs
function helloWorld() {
return "Hello World";
}
在我致电的code.gs下:
Sidebar.html
console.log("This should say Hello World: " + google.script.run.helloWorld())
它返回:
This should say Hello World: undefined
我想念的最明显的东西是什么?
google.script.run
不会返回您期望的普通Apps脚本函数返回的值.相反,您应该使用 .withSuccessHandler(functionToRun)
>
赞:
google.script.run
.withSuccessHandler(functionToRun)
.helloWorld();
function functionToRun(argument) {
console.log("This should say Hello World: " + argument);
}
在此示例中,服务器端Apps脚本函数helloWorld
将运行客户端函数functionToRun()
并将helloWorld()
的结果作为参数传递.
Trying to figure out Google Apps Script for making Google docs addons. I have:
Code.gs
function helloWorld() {
return "Hello World";
}
under code.gs which I call in:
Sidebar.html
console.log("This should say Hello World: " + google.script.run.helloWorld())
It returns:
This should say Hello World: undefined
What is the obvious thing I am missing?
google.script.run
won't return a value like you'd expect a usual Apps Script function to. Instead, you should use .withSuccessHandler(functionToRun)
Like this:
google.script.run
.withSuccessHandler(functionToRun)
.helloWorld();
function functionToRun(argument) {
console.log("This should say Hello World: " + argument);
}
In this example, the server-side Apps Script function helloWorld
will run the client-side function functionToRun()
and pass the result of helloWorld()
as an argument.
这篇关于google.script.run不返回字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!