I wrote a small script in Google Apps Script that creates an array, and when you press a button it should add "test" to the array, and then print the whole array. So when you press the button for the first time it should display 1 "test". When you press it for the second time it should display the first test plus the new array which should contain 2 "test", so a total of 3 "test". But it doesn't. Somehow when it goes out of the function 'buttonPress' the whole array is deleted or something. Can someone explain this? Thanks!
var list = new Array;
function doGet() {
var app = UiApp.createApplication()
var panel = app.createVerticalPanel().setId('id')
var button = app.createButton('Button')
var handler = app.createServerHandler('buttonPress')
button.addClickHandler(handler)
app.add(panel)
panel.add(button)
return app;
}
function buttonPress(){
list.push('test')
var app = UiApp.getActiveApplication()
var panel = app.getElementById('id')
var panel2 = app.createVerticalPanel()
var length = list.length
for(var i = 0; i< length; i++){
panel2.add(app.createHTML(list[i]))
}
}