【发布时间】:2015-07-11 00:50:50
【问题描述】:
我有两个 Google Apps 脚本项目,都是电子表格类型。
让我们调用一个服务器和另一个客户端。
我想从 Server 公开一些函数,以便我可以从 Client 调用它们。
图书馆似乎非常适合这一点。
不幸的是,当我使用 Resources --> Libraries... 菜单选项将 Server 库添加到 Client 时,东西中断了。
注意,即使 Server 库被添加到 Client,我实际上从未使用任何 Server 库函数。 (事实上 Server Code.gs 完全是空白的。)
服务器 Code.gs
//nothing, totally blank, these are test projects created find out what is wrong
客户 Code.gs
//This is our entry point
//It instantiates the Sidebar from Sidebar.html
function test()
{
SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutputFromFile('Sidebar')
.setSandboxMode(HtmlService.SandboxMode.IFRAME));
}
function testReturn()
{
Logger.log("doTest() called");
return 1;
}
客户端 Sidebar.html
<script>
function yay(d)
{
alert('yay: ' + d);
}
function boo(d)
{
alert('boo: ' + d);
}
google.script.run.withFailureHandler(boo).withSuccessHandler(yay).testReturn();
</script>
应该发生什么:
-
我们调用 Client.test()。
这会从 Sidebar.html 中打开一个侧边栏
边栏运行:
google.script.run.withFailureHandler(boo).withSuccessHandler(yay).testReturn(); -
这应该从 Client Code.gs 调用
testReturn()当
testReturn()完成(或没有完成)... 应该调用
yay(d)或boo(d)。
很简单……
所以当我们附加了 NO 库时,yay(d) 会被调用! (在这种情况下使用d = 1)
但是当我们确实附加了一个库时,boo(d) 会被调用
d = ScriptError:很抱歉,发生服务器错误。请稍等,然后重试。
另外,我相信testReturn() 永远不会运行,因为它不会出现在日志中。
我做错了什么?这是 Google 方面的错误吗?
我公开了测试项目:
总而言之,我不明白为什么简单地添加共享库会破坏 google.script.run.... 功能。特别是因为图书馆是空白的。
【问题讨论】:
标签: google-apps-script google-sheets shared-libraries libraries