如何向元素添加自定义小部件 [英] How to add a custom widget to an element

查看:30
本文介绍了如何向元素添加自定义小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GWT RootPanel.get("id") 不返回嵌入在 HTML 元素中的 div 标签.

GWT RootPanel.get("id") doesnt return me the div tags which are embedded in HTML elements.

例如.<身体><表格><tr><td><div id="x"/><td>...</table>...

ex. <body> <table> <tr> <td> <div id="x" /><td>...</table> ...

如何访问此 div 标签和添加小部件".

How do I get access to this div tag and "Add a widget".

我尝试的其中一件事是从小部件或 widget.getElement() 获取元素,并将其添加到将此元素附加到从 DOM.getElementById() 获取的元素中.

One of the things I tried was to get the element from the widget or widget.getElement() and add this to the append this element to an element gotten from DOM.getElementById().

小部件确实被添加了,但是,所有鼠标点击都丢失了并且小部件不再响应.小部件是菜单项的组合,因此鼠标点击会导致菜单项下降,但它只会选择文本.

The widget does get added, however, all mouse clicks are lost and widget no longer responds. The widget is a composite of menu item, so the mouse clicks cause the menu item to drop but it just selects the text.

推荐答案

如果第一句话中的HTML 元素"实际上是指HTML 小部件",那么您应该改用 HTMLPanel 小部件,然后只需使用它的 add(Widget,String)add(Widget,Element) 方法在现有子元素中添加您的小部件.

If by "HTML element" in your first sentence you actually mean "HTML widget", then you should use an HTMLPanel widget instead, and then simply use its add(Widget,String) or add(Widget,Element) method to add your widget within an existing sub-element.

如果您实际上是在谈论不能将具有现有父小部件的小部件添加到分离列表中"断言错误,那么从 GWT 2.3 开始,您现在可以 在 HTMLPanel 中包装一个现有的 DOM 元素,然后使用与上面相同的 add 方法:

If you're actually talking about the "A widget that has an existing parent widget may not be added to the detach list" assertion error, then starting with GWT 2.3, you can now wrap an existing DOM element within an HTMLPanel, and then use the same add methods as above:

HTMLPanel container = HTMLPanel.wrap(Document.get().getElementById("container"));

这篇关于如何向元素添加自定义小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆