gpt4 book ai didi

javascript - google app脚本中的webapp javascript函数

转载 作者:行者123 更新时间:2023-11-30 18:59:38 25 4
gpt4 key购买 nike

我不是英语用户,但我正在尝试正确书写。请得到这个

我要

A== Google 应用程序脚本 .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 库

我该怎么做?

最佳答案

不能从服务器调用客户端函数,唯一的异常(exception)是为客户端发起的对服务器函数的调用指定的成功或失败处理程序。请注意,您的服务器端代码无法知道哪个客户端函数被注册为响应处理程序,或者即使根本没有注册一个。

所以不,您不能“只是”从 .gs 文件中调用 .html 定义的函数。

请查看 HTMLService guide and API reference

// 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 来使用它。

关于javascript - google app脚本中的webapp javascript函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59646440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com