如何获取包装给定DOM元素的GWT小部件? [英] How do I obtain the GWT widget that wraps a given DOM element?

查看:163
本文介绍了如何获取包装给定DOM元素的GWT小部件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当发生点击事件时,我想确定点击哪个小部件。请注意,出于性能原因,我特意不想在每个小部件中添加点击处理程序。

When a click event occurs, I want to determine which of my widgets was clicked. Note that, for performance reasons, I specifically don't want to add click handlers to each of my widgets.

获取被点击的元素很容易将是本地事件的事件目标),但是如何找到相应的小部件?

It's easy enough to obtain the element that was clicked (it'll be the event target of the native event), but then how do I find the corresponding widget?

推荐答案

没有标准功能,afaik。但是您可以按照与GWT的 com.google.gwt.user.client.ui.Tree 类中的相似方式执行此操作。

There is no standard functionality for it, afaik. But you can do it in a similar way as is done in GWT's com.google.gwt.user.client.ui.Tree class.

基本上它通过首先从您的根Widget的元素收集元素链到单击的Widget的元素(请参阅私有方法 collectElementChain 在Tree类中)。通过这个元素链,Widget通过从根部件向下移动到点击的Widget(参见Tree类中的私有方法 findItemByChain )。

Basically it work there by first collecting the chain of Elements from the Element of your root Widget to the element of the Widget that clicked (see private method collectElementChain in Tree class). With this chain of Elements the Widget is found by traversing from the Root widget down to the Widget clicked (see private method findItemByChain in the Tree class).

这适用于Tree,因为每个Widget / Element的子项的Widget和Element索引都匹配,因为它只允许一个特定的小部件集作为TreeItem的。

This works for Tree because the Widget and Element index of the children of each Widget/Element match, and because it only allows a specific widget set as TreeItem's.

这篇关于如何获取包装给定DOM元素的GWT小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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