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

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

问题描述

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


< body>
< table> < TR> < TD> < div id =x/><td>...</table> ...



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

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

小部件会被添加,但是,所有鼠标点击都会丢失,小部件不再响应。该小部件是菜单项的组合,因此鼠标单击会导致菜单项丢弃,但它只是选择文本。 解决方案

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



你实际上是在谈论有一个现有的父窗口部件的部件可能不会被添加到分离列表断言错误,然后从GWT 2.3开始,你现在可以在HTMLPanel中包装现有的DOM元素,然后使用与上面相同的 add 方法:

  HTMLPanel容器= HTMLPanel。包裹(Document.get()的getElementById( 容器)。); 


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

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

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

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.

解决方案

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.

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天全站免登陆