2012-09-05 49 views
0

我試過這個小代碼在UI服務中測試setTag()getTag()(在垂直面板上)。我不知道爲什麼它不起作用......有什麼建議嗎?如何正確使用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 
} 
+0

我懷疑這些是相同的.forTargets(txt2).setText(panel.getTag())和.forTargets(txt2).setText('開始空'),因爲它運行客戶端而不是服務器端。但這是一個猜測。 – eddyparkinson

+0

謝謝但沒有'.forTargets(txt2).setText('start empty')......''start empty'這樣的行只能作爲初始數據而沒有處理程序。 –

回答

0

我覺得這裏的問題是,按一下按鈕使用的客戶端處理程序。 setText()只接受一個靜態字符串,它被設置爲「開始空」。如果你想將它設置爲標籤的當前值,那麼你需要使用服務器處理程序。

+0

謝謝:-)很高興知道... –

相關問題