1
 @UiHandler("addDynamicTextboxbutton")
  void addMoreTextbox(ClickEvent event) {


     textboxplaceholder.add(new TextBox(),"textboxplace");

 }

单击 addDynamicTextboxbutton 按钮时,将执行此方法并创建新的文本框。如何拥有另一个按钮,以便在单击时从每个“textbox()”中获取所有值?或者是否有必要输入名称“新文本框(“名称”)”以便我可以获得它们的所有值?这样做的最佳做法是什么?

4

2 回答 2

2

If textboxplaceholderis and extend of a ComplexPanel,例如,FlowPanel您可以简单地遍历 的子级FlowPanel

for (Widget w: textboxplaceholder) {
   if (w instanceof TextBox) {
     // do something value: ((TextBox)w).getValue();
   }
}
于 2010-11-15T14:13:27.967 回答
1

您可以使用集合来存储新添加TextBox的内容,以后可以从中获取所有值。像这样的东西:

public class Test extends Composite {

    private static TestUiBinder uiBinder = GWT.create(TestUiBinder.class);

    interface TestUiBinder extends UiBinder<Widget, Test> {}

    @UiField
    FlowPanel textboxplaceholder;
    @UiField
    Button addDynamicTextboxbutton;
    private LinkedList<TextBox> boxes;

    public Test() {
        initWidget(uiBinder.createAndBindUi(this));
        boxes = new LinkedList<TextBox>();
    }

    @UiHandler("addDynamicTextboxbutton")
    void addMoreTextbox(ClickEvent event) {
        TextBox box = new TextBox();
        textboxplaceholder.add(box);
        boxes.add(box);
    }
}

遍历存储在其中的框boxes以获取所有值。

于 2010-11-15T13:33:40.910 回答