自动刷新Google Apps脚本的webapp用户界面? [英] Auto refresh Google Apps Scripts webapp UI?

查看:120
本文介绍了自动刷新Google Apps脚本的webapp用户界面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Google Apps脚本创建了一个简单的网络应用.用户界面仅显示了几个在FusionTable中不断更新的数字.一个自定义数据采集系统正在我家本地运行,并每分钟将新结果发送到FusionTable.我希望每隔一分钟更新一次我的GAS Web应用程序上的用户界面,以便显示新的数字.

I have created a simple webapp using Google Apps Scripts. The UI simply displays a couple of numbers being continuous updated in a FusionTable. A custom data acquisition system is running locally in my house and sending new results every minute up to the FusionTable. I wish to update the UI on my GAS webapp at one-minute intervals so that the new numbers are displayed.

我已经解决了一半的问题,方法是运行时间驱动程序触发器以定期从FusionTable中获取数据并将数字存储在脚本自己的ScriptDb中.因此,这可以很好地将我的数据放置在正确的邻域中.但是我仍然看不到如何用新数据定期更新UI中的文本框.

I have half of the problem solved by running a time-driver trigger to periodically grab data from the FusionTable and store the numbers in my script's own ScriptDb. So this works fine to get my data in the right neighborhood. But I still do not see how to periodically update a textbox in my UI with the new data.

到目前为止,我已经在UI上手动配置了刷新按钮,用户可以单击该按钮使用ScriptDb中存储的最新数字来更新显示.我是如此亲密,我可以品尝到它!

So far I have manually configured a refresh button on the UI that user can click to update the display with the most recent numbers stored in the ScriptDb. I am so close I can taste it!

有人有主意吗?

推荐答案

您可以使用UiInstance.addTimer方法进行自动刷新,但是该方法没有记录,并且可能不受支持.

You can use the UiInstance.addTimer method for auto refresh, but it's not documented and maybe not supported.

其语法为UiInstance.addTimer( ServerHandler , interval);

请参见下面的示例代码.

See the sample code below.

function doGet(e) {

  var app = UiApp.createApplication();

  

  app.add(app.createLabel(new Date()).setId("label"));

  

  app.addTimer(app.createServerHandler("update") , 1000);

  

  return app;

}



function update(e){

  var app = UiApp.getActiveApplication();

  app.getElementById("label").setText(new Date());

  app.addTimer(app.createServerHandler("update") , 1000);


  return app;

}

可以在此处找到.

这篇关于自动刷新Google Apps脚本的webapp用户界面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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