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

标签 javascript google-apps-script

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

我要

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/

相关文章:

javascript - 在 Google AdWords 中创建可重复使用的函数

javascript - Angular 模板路由不起作用

javascript - 如何使用网络套接字

javascript - 在没有 Controller 的情况下将变量传递给 AngularJS 中的指令

javascript - 在 Angularjs 中多次使用 ngInclude

javascript - 在 Google Apps 脚本 (JavaScript) 中获取特定字符串格式的第二天日期

javascript - 如何在javascript中调整音频文件的音量

google-apps-script - 以编程方式打开打印预览对话框?

javascript - Google 脚本 : Email automisation: No bugs, 但代码仍然无法工作

javascript - 如何在 JavaScript 中引用今天的日期?