考虑以下简单的代码
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:
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;
}
一种选择比另一种更好吗?