您必须“返回”才能有效关闭uiInstance,需要return
才能反映您对用户界面所做的任何更改,包括关闭它。
尝试
return uiInstance.close();
编辑您的评论如下:
了UiApp情况下,只能从一个处理功能被关闭,我认为这是你如何使用它(但我可能错了)。
下面是一个小的代码示例:
function displayDialog() {
var uiInstance = UiApp.createApplication()
.setWidth(130)
.setHeight(130);
uiInstance.add(uiInstance.createLabel("foo"));
var handler = uiInstance.createServerHandler('closeDialog');
uiInstance.add(uiInstance.createButton('close',handler));
SpreadsheetApp.getUi().showModalDialog(uiInstance, 'bar');
}
function closeDialog(){
return UiApp.getActiveApplication().close();
}
还有一个棘手的变通方法,可以在“模拟”的用户动作。它使用某些小部件的属性在更改值时触发处理函数。在下面的示例中,我使用了一个复选框来启动过程
当doStuf中的任务完成时,它将关闭对话框。
function displayDialog() {
var uiInstance = UiApp.createApplication()
.setWidth(130)
.setHeight(130);
uiInstance.add(uiInstance.createLabel("foo"));
var handler = uiInstance.createServerHandler('doStuf');
var chk = uiInstance.createCheckBox().setValue(true).setId('chk').setVisible(false);
chk.addValueChangeHandler(handler);
uiInstance.add(chk);
chk.setValue(false,true)// This actually calls the doStuf function (using the handler)
SpreadsheetApp.getUi().showModalDialog(uiInstance, 'bar');
}
function doStuf(){
Utilities.sleep(5000);// replace with something useful ...
return UiApp.getActiveApplication().close();
}
也许我只是不明白你的意思,我仍然无法使其工作;如果我有一个像{displayDialog();做东西(); closeDialog(); }什么需要closeDialog()看起来像?我还必须改变displayDialog()吗? – 2014-10-12 09:47:23
请参阅编辑 – 2014-10-12 11:01:48
谢谢=)!我需要这个,因为“doStuff”任务需要一段时间才能完成(> 1分钟),并且我希望用户知道它是否还在工作 – 2014-10-13 11:16:21