I would like to offer the opportunity to view output from the same data, in a spreadsheet, TBA http://glasier.hk/blazer/scriptsShop/TBA.html sidebar and, ideally another type of HTML window for output created, for example, with a JavaScript Library like THREE https://threejs.org/examples/#webgl_animation_cloth.
The non Google version I made is a web page with iframes that can be resized, dragged and opened/closed and, most importantly, their content shares the same record object in the top window. So, I believe, perhaps naively, something similar could be made an option inside this established and popular application.
At the very least, the TBA trial has shown me it useful to view and manipulate information from either sheet or TBA https://stackoverflow.com/questions/30628894/how-do-i-make-a-sidebar-display-values-from-cells/56358850#56358850. The facility to navigate large building projects, clone rooms and floors, and combine JSON records (stored in depositories like myjson http://myjson.com/) for collaborative work is particularly inspiring for me.
我尝试过对不同的 HTML 文件使用侧边栏,但事实上只有一个保持打开状态并不是很有用,而且坦率地说,共享记录对象仍然超出了我的能力范围。这就是主要问题。谷歌人是否会考虑额外的窗口类型可能有点雄心勃勃,但我认为值得一问。
您无法在对 HtmlService 的调用之间维护全局变量。当您启动在浏览器中运行的 HtmlService 实例时,启动它的服务器端代码就会退出。
从那时起,控制权就在客户端,在 HtmlService 代码中。如果您随后启动服务器端函数(从客户端使用 google.script.run),则会启动服务器端脚本的新实例,并且不会存储前一个实例 - 这意味着所有全局变量都会重新初始化。
有多种技术可以在调用之间保留值。
- 当然,最简单的方法是首先将其传递给 htmlservice,然后将其作为 google.script.run 的参数传递回服务器端。
- 另一种是使用物业服务来保存你的价值观,当你回去时它们仍然存在,但有一个最大条目大小9k
- 如果您需要更多空间,那么缓存服务可以在单个条目中保存 100k,您可以以相同的方式使用它(尽管有很小的机会它会被清除 - 尽管这对我来说从未发生过)
- 如果您需要更多空间,可以使用一些技术来压缩和/或将单个对象分散到多个缓存条目中 - 如此处所述http://ramblings.mcpher.com/Home/excelquirks/gassnips/squeezer http://ramblings.mcpher.com/Home/excelquirks/gassnips/squuezer。如果您需要更长时间地保存数据,同样的方法支持 Google Drive 或 Google 云存储
当然,您不能传递不可字符串化的对象(例如函数等),但您可以推迟它们的评估并允许初始化的服务器端脚本评估它们,甚至在服务器、客户端或跨项目之间共享相同的代码。
这些文章中描述了一些技术http://ramblings.mcpher.com/Home/excelquirks/gassnips/nonstringify http://ramblings.mcpher.com/Home/excelquirks/gassnips/nonstringify
http://ramblings.mcpher.com/Home/excelquirks/gassnips/htmltemplateresuse http://ramblings.mcpher.com/Home/excelquirks/gassnips/htmltemplateresuse
然而,在您的具体示例中,似乎您想要的全局数据是从外部 api 调用中获取的。无论如何,为什么不直接在客户端检索它呢?如果您需要在服务器端对其执行某些操作,请使用 google.script.run 将其传递到服务器。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)