试图找出用于制作 Google 文档插件的 Google Apps 脚本。
我有:
Code.gs
function helloWorld() {
return "Hello World";
}
在我调用的 code.gs 下:
侧边栏.html
console.log("This should say Hello World: " + google.script.run.helloWorld())
它返回:
This should say Hello World: undefined
我缺少什么明显的东西?
google.script.run
不会像您期望的常用 Apps 脚本函数那样返回值。相反,你应该使用.withSuccessHandler(functionToRun) https://developers.google.com/apps-script/guides/html/reference/run#withsuccesshandlerfunction
像这样:
google.script.run
.withSuccessHandler(functionToRun)
.helloWorld();
function functionToRun(argument) {
console.log("This should say Hello World: " + argument);
}
在此示例中,服务器端 Apps 脚本函数helloWorld
将运行客户端函数functionToRun()
并传递结果helloWorld()
作为一个论点。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)