有什么方法可以从客户端用户界面调用库? [英] Is there any way to call a library from a client side user interface?
问题描述
我正在HTML服务中为Google Apps Script构建用户界面,并且希望能够从脚本的服务器端.gs文件中加载的库中调用函数.客户端对服务器端库的调用似乎不起作用.这可能吗?
I'm building a user interface in HTML Service for Google Apps Script and I want to be able to call functions from a library that is loaded in the server side .gs file of my script. The client side call to the server side library does not seem to work. Is this possible to do?
我对javascript/apps脚本还很陌生,所以如果我误报了这里发生的事情,请原谅.
I'm pretty new to javascript/apps script so excuse me if I'm mis-stating what's happening here.
更新:这是我使用的解决方案
UPDATE: Here's the solution I used
在容器绑定脚本上:
function libraryHandler(functionName){
return eval("libraryIdentifier." + functionName);
}
在库中:
google.script.run.libraryHandler('myLibraryFunctionName(param1,param2,etc.)')
推荐答案
在html所在的同一脚本中创建虚拟"函数.使该虚拟对象调用您的库函数.
Make a "dummy" function in the same script where the html is. Make that dummy call your library function.
这篇关于有什么方法可以从客户端用户界面调用库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!