[英]GWT Clone a widget using DOM.clone
I wish to programatically clone a widget. 我希望以编程方式克隆小部件。 I am able to clone the Element inside the Widget with Dom.clone but I don't seem to be able to create a Widget from this cloned element.
我可以使用Dom.clone克隆Widget中的Element,但我似乎无法从此克隆元素创建Widget。 Is this possible?
这可能吗?
//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);
Is there another way of cloning the Widget? 还有另一种克隆Widget的方法吗?
buttonClone = Button.wrap(buttonCloneElement)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.