簡體   English   中英

GWT Bootstrap預輸入事件偵聽器?

[英]GWT Bootstrap typeahead event listener?

我正在使用GWTBootstrap3 Typeahead小部件。 主要問題是事件沒有取消注冊,並且事件在我加載該組件時捆綁了很多次。 默認情況下會緩存組件。 第一個組件加載觸發事件1次,第二個組件加載觸發事件2次,依此類推。 這引起了很多問題。 我嘗試了HandlerRegistration和removeHandler()無法正常工作。 如果有人找到解決方案,請告訴我。

這是注冊事件的代碼:

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

謝謝

我可以想到兩種選擇:

您可以在productSelect的構造函數中或在調用構造函數的代碼中注冊事件處理程序。 加載組件時不行。

您可以檢查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