如何正确使用setTag()和getTag()?

时间:2012-09-05 20:37:31

标签: google-apps-script

我尝试使用这个小代码来测试UI服务中的setTag()getTag()(在垂直面板上)。我不知道为什么它不起作用......有什么建议吗?

online test

function doGet() {
  var app = UiApp.createApplication();
  var panel = app.createFlowPanel().setId('panel').setTag('start empty');// sets an initial value
  var txt1 = app.createTextBox().setName('txt1').setId('txt1');
  var txt2 = app.createTextBox().setName('txt2').setId('txt2');
  var label = app.createLabel('type in TextBox 1 and then click button');
  var button = app.createButton('click to trigger clienthandler');
  app.add(panel.add(label).add(txt1).add(txt2).add(button));
  var serverHandler = app.createServerHandler("key").addCallbackElement(panel);// this handler synchronizes the tag with textBox1
  txt1.addKeyUpHandler(serverHandler);

  var clientHandler = app.createClientHandler()
  .forTargets(txt2).setText(panel.getTag()).setStyleAttribute('background','red');;// this client handler is to test the getTag()
  button.addClickHandler(clientHandler)

return app
}

function key(e){
  var app = UiApp.getActiveApplication();
  var panel=app.getElementById('panel');
  var txt2=app.getElementById('txt2');
  var txt1val = e.parameter.txt1;//gets textBox value
  panel.setTag(txt1val);// set tag value
  txt2.setStyleAttribute('background','white');// resets to white when entering text
return app
}

1 个答案:

答案 0 :(得分:0)

我认为这里的问题是按钮点击是使用客户端处理程序。 setText()只接受一个静态字符串,该字符串被设置为“start empty”。如果要将其设置为标记的当前值,则需要使用服务器处理程序。

相关问题