0

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

这是我当前的代码:

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;
}
4

1 回答 1

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 字符串与新的小部件一起使用,就会发生不好的事情。

于 2013-08-04T00:18:45.200 回答