3
考慮以下簡單的代碼多少個回調元素?
function doGet(){
var app = UiApp.createApplication();
var panel = app.createVerticalPanel();
var handler = app.createServerHandler('click').addCallbackElement(panel);
var btn = app.createButton('Click', handler);
panel.add(button);
app.add(panel);
return app;
}
有一個單一面板和回調元素是孤面板。然而,當你有許多面板用於不同的目的時,有什麼更好的方法 - 添加多個回調元素或將所有各種面板添加到單個「主」面板中,並添加主面板作爲回調元素。 這些方法的優缺點是什麼?
下面
選項1某些代碼examplee:
function doGet(){
...
var panel1 = app.createVerticalPanel();
var panel2 = app.createVerticalPanel();
var handler = app.createServerHandler('click')
.addCallbackElement(panel1)
.addCallbackElement(panel2) ; // Notice two callback elements added here
var btn = app.createButton('Click', handler);
...
return app;
}
選項2:
function doGet(){
...
var masterPanel = app.createVerticalPanel();
var panel1 = app.createVerticalPanel();
var panel2 = app.createVerticalPanel();
var handler = app.createServerHandler('click')
.addCallbackElement(masterPanel) ;
var btn = app.createButton('Click', handler);
masterPanel.add(panel1).add(panel2); // Master panel has both panels added to it
...
return app;
}
是一種選擇優於其他?