[英]GWT detach widget from DOM and add to Panel
I need to be able to detach a node from the DOM
and attach it to a HorizontalPanel
at runtime using GwtQuery
. 我需要能够从
DOM
分离节点并将其在运行时使用GwtQuery
附加到HorizontalPanel
。
My code looks like this: 我的代码如下所示:
@PageShown
public void pageReady() {
horizontalPanel.add($("#bar1").widget());
horizontalPanel.add($("#bar2").widget());
horizontalPanel.add($("#bar3").widget());
}
Where #bar1
, et. 其中
#bar1
等。 al are already attached in the DOM, what I need to do is that these 3 bars should be piled horizontally so I need to attach them to a HorizontalPanel. Al已经安装在DOM中,我需要做的是将这3个横条水平堆叠,因此我需要将它们附加到HorizontalPanel。
Update: 更新:
After promoting the DOM element into Panel the horizontalPanel
is still empty: 将DOM元素提升到Panel中之后,
horizontalPanel
仍然为空:
<table cellspacing="0" cellpadding="0" data-field="navPanel"><tbody><tr></tr></tbody></table>
$("#bar1")
should be a gwt-widget, otherwise the method widget()
of gQuery will return null. $("#bar1")
应该是gwt-widget,否则gQuery的方法widget()
将返回null。
You can, though, promote certain dom-elements to widgets with gQuery: 不过,您可以使用gQuery将某些dom元素提升为小部件:
// Promote 3 elements attached to the dom to 3 GWT Panel Widgets
$("#bar1, #bar2, #bar3").as(Widgets).panel();
horizontalPanel.add($("#bar1").widget());
horizontalPanel.add($("#bar2").widget());
horizontalPanel.add($("#bar3").widget());
Apart from panel()
which promotes an element to a GWT Panel
, the gQuery Widgets
plugin comes with other predefined methods like label()
textBox()
passwordBox()
and textArea()
. 除了
panel()
促进向GWT的元件Panel
,所述gQuery Widgets
插件有其它预定义的方法等label()
textBox()
passwordBox()
和textArea()
But you can code your own WidgetFactory
to promote any dom element to customized widgets through the method widgets(WidgetFactory)
. 但是,您可以编写自己的
WidgetFactory
来通过方法widgets(WidgetFactory)
将任何dom元素提升为自定义窗口widgets(WidgetFactory)
。
Anyway, if you only want to layout elements in your page, an easier way could be just use css instead of wrapping them into widgets. 无论如何,如果您只想在页面中布局元素,一种更简单的方法可能是使用css而不是将它们包装到小部件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.