本文介绍了GWT使用DOM.clone克隆一个小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望以编程方式克隆一个小部件。我能够用Dom.clone克隆Widget中的Element,但我似乎无法从此克隆的元素中创建Widget。这是可能的吗?
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. 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);
是否有另一种克隆Widget的方法?
Is there another way of cloning the Widget?
推荐答案
buttonClone = Button.wrap(buttonCloneElement)
这篇关于GWT使用DOM.clone克隆一个小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!