如何使用google.script.run? [英] How to use google.script.run?

查看:109
本文介绍了如何使用google.script.run?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的一个项目中使用google.run.script函数,并且它似乎没有触发要运行的函数。

所以我做了一个新项目并测试了一个简单的例子,它完全从 https://developers.google.com/apps-script/guides/html/reference/run



Code.gs

 函数doGet(){
return HtmlService .createHtmlOutputFromFile( '索引');


函数doSomething(){
Logger.log('I was called!');
}

Index.html

 <!DOCTYPE html> 
< html>
< head>
< base target =_ top>
< script>
google.script.run.doSomething();
< / script>
< / head>
< body>
< / body>
< / html>

然而,当我运行doGet()函数时,检查我的日志我没有看到'我是叫'',我不知道如何正确使用google.run.script,所以我可以在另一个项目中使用它。

解决方案

我认为你的脚本能正常工作。 doSomething() google.script.run.doSomething()运行,您可以看到我被称为!在日志中。因此,请确认以下流程。


  1. 关于部署Web Apps。即使在脚本编辑器中直接运行 doGet(),它也不起作用。那时候,请部署为Web Apps。您可以在此处查看如何部署Web Apps的详细信息。

  2. 修改脚本后,必须更新项目版本。由此,Web Apps可以使用最新的脚本。如果您不想更新项目版本,可以通过单击测试Web应用程序的最新代码来获取最新代码,以使用最新脚本。 。这可以在下面看到。


    • 在脚本编辑器中
    • 发布 - >部署为web应用程序
    • 你可以看到测试你的最新代码的web应用程序。在当前的Web应用程序URL:


如果这对您没有用处,对不起。

I am trying to use the google.run.script function in one of my projects and it doesn't seem to be triggering the function to run.

So I made a new project and tested a simple example, copied exactly from https://developers.google.com/apps-script/guides/html/reference/run.

Code.gs

 function doGet() {
  return HtmlService.createHtmlOutputFromFile('Index');
}

function doSomething() {
  Logger.log('I was called!');
}

Index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script>
      google.script.run.doSomething();
    </script>
  </head>
  <body>
  </body>
</html>

However when I run the doGet() function then check my logs I do not see the 'I was called', and I cannot figure out how to correctly use google.run.script so I can use it in another project.

解决方案

I think that your script works fine. doSomething() is run by google.script.run.doSomething(), and you can see I was called! at the log. So please confirm the following flow.

  1. About deploying Web Apps. Even if doGet() is directly run on script editor, it doesn't work. At that time, please deploy as Web Apps. You can see the detail of how to deploy Web Apps is here.
  2. After the script is modified, project version has to be updated. By this, the latest script can be used by Web Apps. If you don't want to update the project version, you can use the latest script by clicking latest code of Test web app for your latest code.. This can be seen below.
    • On script editor
    • Publish -> Deploy as web app
    • You can see "Test web app for your latest code." at "Current web app URL:"

If this was not useful for you, I'm sorry.

这篇关于如何使用google.script.run?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆