2013-02-09 59 views
2

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

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

this,“功能的doGet(E)是GWT等价的onLoad的”,但它不是我的情况,我想dispay页面,做缓慢的部分...

回答

4

Stumbled on this然后我们可以使用它来实现一个pseudo-onLoad事件。

复选框上的setValue函数有an optional parameter来触发valueChanged处理函数。因此,您可以通过编程方式触发valueChanged处理函数,该函数允许您在处理程序同时被调用时返回应用程序(最初加载它)。

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; 
} 
+0

这真是一个好;-)也许你可以加一点关于[复选框的软触发能力]的解释(https://developers.google.com/apps-script/class_checkbox?hl=en# setValue)你使用的是 – 2013-02-09 19:37:13

+0

聪明的解决方法,像魅力一样工作。谢谢! – 2013-02-09 20:33:52

0

其他几个小部件有setValue(value, fireEvents)方法,例如。 TextBox,PasswordTextBox等等。看起来好像没有什么独特的关于CheckBox部件在实现这种技术。