google.script.run不返回字符串 [英] google.script.run not returning string

查看:90
本文介绍了google.script.run不返回字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图弄清楚用于制作Google文档插件的Google Apps脚本. 我有:

Code.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  

我想念的最明显的东西是什么?

解决方案

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

赞:

    google.script.run
        .withSuccessHandler(functionToRun)
        .helloWorld();

    function functionToRun(argument) {
        console.log("This should say Hello World: " + argument);
    }

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

Trying to figure out Google Apps Script for making Google docs addons. I have:

Code.gs

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

under code.gs which I call in:

Sidebar.html

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

It returns:

This should say Hello World: undefined  

What is the obvious thing I am missing?

解决方案

google.script.run won't return a value like you'd expect a usual Apps Script function to. Instead, you should use .withSuccessHandler(functionToRun)

Like this:

    google.script.run
        .withSuccessHandler(functionToRun)
        .helloWorld();

    function functionToRun(argument) {
        console.log("This should say Hello World: " + argument);
    }

In this example, the server-side Apps Script function helloWorld will run the client-side function functionToRun() and pass the result of helloWorld() as an argument.

这篇关于google.script.run不返回字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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