UiApp加载后调用函数(Javascript onLoad等效) [英] Call function after UiApp is loaded (Javascript onLoad equivalent)

查看:117
本文介绍了UiApp加载后调用函数(Javascript onLoad等效)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要一些电子表格数据的UiApp表单(检索速度很慢)。我想要实现的是像往常一样加载视图,并在显示后执行一些操作,例如调用服务器处理程序来获取数据并在完成后更新视图。这是可能的吗?

I have a UiApp form that requires some spreadsheet data (slowish retrieval). What I'd like to achieve is load the view as usual and after it has been displayed do something like calling a server handler that gets the data and updates my view when it's done. Is that possible?

我环顾四周,但没有找到任何东西。

I looked around but I didn't find anything.

根据 ,函数doGet(e)是onLoad的GWT等价物,但它并不适用于我的情况,因为我希望只显示页面,而只是执行慢速部分...

According to this, "function doGet(e) is the GWT equivalent of onLoad", but it's not in my case as I would like to dispay the page and only then do the slow part...

推荐答案

我们可以使用它来实现一个伪onLoad事件。

Stumbled on this which we could then use to implement a pseudo-onLoad event.

setValue

The setValue function on checkboxes has an optional parameter to fire the valueChanged handler. So you can programmatically trigger the valueChanged handler, which allows you to return the app (load it initially) while the handler is being invoked simultaneously.

function doGet() {
  var app = UiApp.createApplication();

  var label = app.createLabel('Loading the data from the spreadsheet.')
                 .setId('statusLabel')
  app.add(label);

  var handler = app.createServerHandler('loadData');
  var chk = app.createCheckBox('test').addValueChangeHandler(handler).setVisible(false).setValue(true,true).setId('chk');
  app.add(chk);

  return app;
}

function loadData(e) {
  var app = UiApp.getActiveApplication();

  Utilities.sleep(3000); //placeholder for some function that takes a long time.

  var label = app.getElementById('statusLabel');
  label.setText("Loaded the data from the spreadsheet");

  return app;
}

这篇关于UiApp加载后调用函数(Javascript onLoad等效)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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