RemoveEventListener click vaadin

huangapple go评论73阅读模式
英文:

RemoveEventListener click vaadin

问题

我有以下的代码:

label.getElement().addEventListener("click", e->{
            System.out.print("\nHello there\n");
        });

但是我的应用有时会向相同的标签添加不同的点击监听器。在其他一些框架中,比如 Android(vaadin 按钮的行为相同),添加第二个监听器会移除旧的监听器。然而,在这种情况下却不会移除旧的监听器。

在这种情况下,我应该如何移除监听器,以便只保留一个点击监听器。

英文:

I have the following code:

label.getElement().addEventListener("click", e->{
            System.out.print("\nHello there\n");
        });

But my app will, at times, add a different click listener to the same label. In some other frameworks, like android (the vaadin button acts the same), adding a second listener would remove the old one. However, in this case it does not.

How would I go about removing the listener in this case. So I only have a single click listener.

答案1

得分: 3

addEventListener方法返回一个DomListenerRegistration实例,稍后您可以使用该实例来移除特定监听器(使用remove()方法)。

Vaadin没有提供一次性移除所有监听器的方法。

英文:

The addEventListener method returns a DomListenerRegistration instance that you can use later on to remove that specific listener (using the remove() method).

Vaadin doesn't offer any way of removing all listeners.

huangapple
  • 本文由 发表于 2020年10月21日 19:09:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/64462273.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定