Google Apps脚本面板删除

时间:2013-08-03 20:05:04

标签: google-apps-script

我想使用网页分阶段收集数据。当用户点击下一步时,我希望从应用中删除当前面板并添加新面板,我无法使其正常工作。

这是我目前的代码:

function doGet() {
//Create Application
var app = UiApp.createApplication();
//Set Application Title
app.setTitle("New Lead Form");

/////////////////////////////////Step 1///////////////////////////////////            

// Create a Panel for Step 1 Data


var nextbuttonstep1 = app.createButton("Next");

// Create the entry form, a 6 x 2 grid with text boxes for First Name, Last Name, Phone     Number, Email, & Property State that is then added to a vertical panel
var grid = app.createGrid(5, 2);
var propertystate = app.createListBox().setName('propertystate').setId('propertystate') 
                  propertystate.addItem('AL');
                  propertystate.addItem('FL');
                  propertystate.addItem('IN');
                  propertystate.addItem('KY');

grid.setWidget(0, 0, app.createLabel('First Name:'));
grid.setWidget(0, 1, app.createTextBox().setName('firstname').setId('firstname'));
grid.setWidget(1, 0, app.createLabel('Last Name:'));
grid.setWidget(1, 1, app.createTextBox().setName('lastname').setId('lastname'));
grid.setWidget(2, 0, app.createLabel('Phone Number:'));
grid.setWidget(2, 1, app.createTextBox().setName('phonenumber').setId('phonenumber'));
grid.setWidget(3, 0, app.createLabel('Email Address:'));
grid.setWidget(3, 1,    app.createTextBox().setName('emailaddress').setId('emailaddress'));
grid.setWidget(4, 0, app.createLabel('Property State:'));
grid.setWidget(4, 1, propertystate);

// Create a vertical panel and add the grid to the panel
var step1panel = app.createFlowPanel();
step1panel.add(grid);
step1panel.add(nextbuttonstep1);
app.add(step1panel)
var handler = app.createServerHandler('proceedtostep2');
handler.addCallbackElement(step1panel)
nextbuttonstep1.addClickHandler(handler);


return app;
}

function proceedtostep2(eventInfo) {

var parameter = eventInfo.parameter;
var panel =parameter.step1panel; 
var app = UiApp.getActiveApplication();

app.remove(panel);

return app;
}

1 个答案:

答案 0 :(得分:3)

面板不显示为参数,只显示输入字段。您必须使用它的ID检索要删除的面板:

...
// Create a vertical panel and add the grid to the panel
var step1panel = app.createFlowPanel().setId('someUniqueIdString');
...

...
function proceedtostep2(eventInfo) {
  var app = UiApp.getActiveApplication();
  app.remove(app.getElementById('someUniqueIdString'));
  return app;
}

但是从应用程序窗口中删除所有元素不会关闭窗口。窗口只保持丑陋状态。 删除后添加其他小部件即可,但您应该使用一些新的ID。如果你将新的ID字符串与新的小部件一起使用会发生坏事。