【问题标题】:google.script.run not returning stringgoogle.script.run 不返回字符串
【发布时间】:2017-01-07 23:43:31
【问题描述】:

试图找出用于制作 Google 文档插件的 Google Apps 脚本。 我有:

代码.gs

function helloWorld() {
    return "Hello World";
}  

在我调用的code.gs下:

Sidebar.html

console.log("This should say Hello World: " + google.script.run.helloWorld()) 

返回:

This should say Hello World: undefined  

我缺少什么明显的东西?

【问题讨论】:

    标签: javascript jquery google-apps-script google-docs


    【解决方案1】:

    google.script.run 不会像您期望的通常的 Apps 脚本函数那样返回值。相反,您应该使用.withSuccessHandler(functionToRun)

    像这样:

        google.script.run
            .withSuccessHandler(functionToRun)
            .helloWorld();
    
        function functionToRun(argument) {
            console.log("This should say Hello World: " + argument);
        }
    

    在此示例中,服务器端应用程序脚本函数 helloWorld 将运行客户端函数 functionToRun() 并将 helloWorld() 的结果作为参数传递。

    【讨论】:

    • 我想我明白了。点击可能需要一点时间,但我的代码现在可以工作了,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-14
    • 2020-04-13
    • 2023-03-30
    • 2013-04-25
    • 2012-11-21
    相关资源
    最近更新 更多