javascript - 谷歌应用脚本中的 webapp javascript 函数
问题描述
我不是英语用户,但我正在尝试正确书写。请得到这个
我想要
A== 谷歌应用脚本 .gs
var result = solvethis(1,3);
Logger.Log(result) // 4
B== webapp javascript .html
<script>
function solvethis(a,b){
return a+b
}
</script>
我为什么要这样做。
我想使用一些带有 make javascript => alasql.js 的数据库
但在 .gs -> alasql.js 中不起作用。
所以我必须使用html。
我不知道很多,但我知道 dget。
1===.gs
function dget(e){
return HtmlService.createTemplateFromFile("index").evaluate();
}
alasql(select * )
2===.html
<script src="https://cdn.jsdelivr.net/npm/alasql@0.5"></script>
---------------- => 它不起作用。
我不想直接打开 webapp 页面。但我想要 .gs 中的 js 库
我怎样才能做到这一点?
解决方案
您不能从服务器调用客户端函数,唯一的例外是为客户端发起的对服务器函数的调用指定的成功或失败处理程序。请注意,您的服务器端代码无法知道哪个客户端函数已注册为响应处理程序,或者即使根本没有注册。
所以不,你不能“只是”从你的 .gs 文件中调用一个 .html 定义的函数。
// client.html (you write the UI and other stuff for the sidebar or modal or webapp page)
function calledByServer(serverOutput) {
console.log({ serverOutput }); // or whatever you want to do with the response
}
function doServer(...argsArray) { //invoke somehow, e.g. a client-side click handler
google.script.run
.withSuccessHandler(calledByServer)
.ServerSideFunctionName(argsArray);
}
// Code.gs
function ServerSideFunctionName(foo) {
console.log(foo); // Stackdriver logging, since Logger is instance specific
// Do something with foo
return someValueToSendToClient;
}
如果您想使用该库,则必须在纯客户端代码中构建并使用 UI 来使用它。
推荐阅读
- python - 如何在连体网络中使用两个相同网络的加载权重进行预测?
- assembly - 组装 68k - CMP 未按预期工作
- node.js - 为什么这会返回两组数据?
- salesforce - 我们可以在 js 文件中多次使用“Apex Wire Method to Function”类型吗?
- jboss - Wildfly 18 部署战争错误 - java.net.ConnectException: WFLYPRT0053: 无法连接到远程+http://hostname:port
- javascript - 使用 chart.js 创建条形图,其中每个条形的空间相同,调整了整体图表大小
- arrays - 连接两个函数参数
- python - 如何创建多维 ctypes 数组并将其作为参数传递?
- mysql - 如何将全名列插入名称和姓氏列MYSQL
- python - 如何从另一个 python 脚本停止和重新启动 python 脚本?