0

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

在线测试

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
}
4

1 回答 1

0

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

于 2012-09-12T22:54:24.273 回答