简体   繁体   English

GWT Bootstrap预输入事件侦听器?

[英]GWT Bootstrap typeahead event listener?

I am using GWTBootstrap3 Typeahead widget. 我正在使用GWTBootstrap3 Typeahead小部件。 The main problem is the event is not getting deregistered and the events are bundling up as many times i load the component. 主要问题是事件没有取消注册,并且事件在我加载该组件时捆绑了很多次。 The components are cached by default. 默认情况下会缓存组件。 The first component load triggers event 1 time and in second time component load triggers 2 times and so on. 第一个组件加载触发事件1次,第二个组件加载触发事件2次,依此类推。 It's causing a lot of problem. 这引起了很多问题。 I have tried HandlerRegistration and removeHandler() its not working. 我尝试了HandlerRegistration和removeHandler()无法正常工作。 If any body found a solution please let me know. 如果有人找到解决方案,请告诉我。

Here is the bit of code where the event is registered: 这是注册事件的代码:

HandlerRegistration typeAheadListener = 
    productSelect.addTypeaheadSelectedHandler(new TypeaheadSelectedHandler<Part>() {
    @Override public void onSelected(TypeaheadSelectedEvent<Part> event) { 
        selectedPart = event.getSuggestion().getData(); // Handling the event 
    }
});

Thanks 谢谢

I can think of two options there: 我可以想到两种选择:

You can register the event handler in the productSelect's constructor, or in the code where you call the constructor. 您可以在productSelect的构造函数中或在调用构造函数的代码中注册事件处理程序。 Not when the component is loaded. 加载组件时不行。

You can check the HandlerRegistration API, it gives a tip on how a handler can deregister itself: 您可以检查HandlerRegistration API,它提供了有关处理程序如何注销自身的提示:

new MyHandler() {
    HandlerRegistration reg = MyEvent.register(eventBus, this);

    public void onMyThing(MyEvent event) {
        /* do your thing * /
        reg.removeHandler();
    }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM