我试图让一个按钮多次触发(即多次点击),但它似乎不起作用。任何帮助将不胜感激。理论上它应该触发多次,但是当我在日志中检查它时它只会触发一次
function a
{
...
var addcolumnspanel = app.createHorizontalPanel().setId("addcolumnspanel");
var addbuttonhandler = app.createServerHandler("addcolumn");
var addbutton = app.createButton().setId("btnaddcolumn").setText("Add another column").addClickHandler(addbuttonhandler);
...
return app;
}
function addcolumn()
{
...//Do some stuff
return app;
}
这是一个更精确的代码示例
//set global var
var counter = 1;
var ss = SpreadsheetApp.getActiveSpreadsheet();
//Set up the Menu bar
function onOpen() {
// Logger.clear();
var menuEntries = [ {name: "demo", functionName: "myFunction"}];
ss.addMenu("Demo", menuEntries);
}
function myFunction() {
var myapp = UiApp.createApplication().setHeight(430).setWidth(800);;
var button = myapp.createButton("Clicky");
var myhandler = myapp.createServerHandler("secondfunction");
var myhandler = button.addClickHandler(myhandler)
myapp.add(button);
ss.show(myapp);
}
function secondfunction()
{
counter++;
Logger.log(counter);
}