我尝试了这个小代码来测试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
}