在阅读了与 UI 服务的甲板面板相关的 GAS 文档后,我了解到一旦将元素添加到甲板面板,它就会变得不可见,如果从中删除元素,它将再次可见。我写了一些测试代码,但是当我从甲板面板中删除它时,我无法使面板可见。有什么见解吗?
这是代码:
function doGet() {
var app = UiApp.createApplication();
var globalPan = app.createAbsolutePanel();
app.add(globalPan);
var deckPanel = app.createDeckPanel().setId('deck').setSize(300, 300).setTitle('DeckPanel').setAnimationEnabled(true);
globalPan.add(deckPanel);
globalPan.add(app.createHorizontalPanel().add(app.createLabel('Element to add to DeckPanel')).setId('visiblePan'));
var hidden = app.createHidden('hEl', 'visible').setId('hEl').setName('hEl');
app.add(hidden);
app.add(app.createButton('Add to DeckPanel').setId('button').addClickHandler(app.createServerHandler('handlerFunction').addCallbackElement(hidden)));
return app;
}
function handlerFunction(eventInfo) {
var app = UiApp.getActiveApplication();
var parameter = eventInfo.parameter;
var state = parameter.hEl;
if (state == 'visible'){
app.getElementById('deck').add(app.getElementById('visiblePan'));
app.getElementById("button").setText("Remove from DeckPanel");
app.getElementById('hEl').setValue('hidden');
};
else{
app.getElementById('deck').remove(0);
app.getElementById("button").setText("Add to DeckPanel");
app.getElementById('hEl').setValue('visible');
};
return app;
}