按下按钮时我想要脚本立即改变颜色,但实际上它在copyProject脚本完成后改变它的颜色,copyProject函数大约需要40秒
我曾经想过拆分处理函数,让它在按下时更改颜色,在运行copyProject函数之前,有什么想法吗?
function copyProject(e)
{
var app=UiApp.getActiveApplication();
var button=app.getElementById("button");
process(app,button);
var sourceProjectID=e.parameter.id;
copProject(sourceProjectID);
return app.close();
}
function process(app,button)
{
button.setStyleAttribute("color", "red").setText("Processing");
return app;
}
由于
答案 0 :(得分:1)
以下是模拟所需行为的按钮上的客户端服务器和serverHandler示例:按钮在您单击时更改颜色...在long serverHandler函数之后显示消息。
function doGet(){
var app = UiApp.createApplication();
var handler = app.createServerHandler('test');
var cHandler = app.createClientHandler();
var btn = app.createButton('click this button').addClickHandler(handler).addClickHandler(cHandler);
cHandler.forEventSource().setStyleAttributes({'color':'red'})
app.add(btn);
return app
}
function test(e){
var app = UiApp.getActiveApplication();
app.add(app.createLabel('operation completed'));
Utilities.sleep(4000);
return app;
}
实时测试here
答案 1 :(得分:0)
处理在服务器上进行,因此它只会在完成此过程后重新绘制应用程序,并且您的用户界面无法响应。
使用UI并使其响应的正确方法是使用客户端处理程序,使您可以动态更新UI。另请参阅验证器,它们可以在您处理它们之前验证输入,而无需转到服务器。
https://developers.google.com/apps-script/uiapp#ClientHandlers
https://developers.google.com/apps-script/uiapp#Validators
如果我能帮助你,请告诉我