我希望以编程方式克隆小部件。我可以使用Dom.clone克隆Widget中的Element,但我似乎无法从此克隆元素创建Widget。这可能吗?
//somewhere in onModuleLoad()...
Button button = new Button("Original");
RootPanel.get().add(button);
//.....later on...
Element buttonCloneElement = DOM.clone(button.getElement(), true);
Widget buttonClone;
buttonClone = new Button(buttonCloneElement); //FAIL - No such constructor
buttonClone.setElement(buttonCloneElement); //FAIL - No such setter method
//This may work but looks messy to me
buttonClone.getElement().setInnerHTML(button.getElement().getInnerHTML());
//add the clone to the root panel??
RootPanel.get().add(buttonClone);
还有另一种克隆Widget的方法吗?
答案 0 :(得分:9)
buttonClone = Button.wrap(buttonCloneElement)