简体   繁体   中英

GWT Suggestbox: Older callbacks overwrite newer ones

The Context

I am using a SuggestBox with a custom SuggestOracle that suffers from a poor performance.

I type "a" and all results that start with the letter "a" will be returned as suggestions. Since there are a lot of results, the suggestions are shown with a short delay of a few seconds.

But in the meantime, I have continued to type. So now I have type "ab", and there are significantly less results than "a" alone. So the suggestions show almost instantly.

The problem

After the "ab" suggestions are shown, the callback from "a" returns and overwrites the "ab" suggestions. In the end I have a list of suggestions that does not match the word I have typed.

My questions

  • Is there a way to prevent older callbacks to overwrite newer ones ?
  • If not, is there a way to wait for at least 3 letters before the suggestions mechanism is triggered ?
  • Any other solution idea ?

Is there a way to prevent older callbacks to overwrite newer ones ?

When your asynchronous process comes back, check that the suggestbox's current text matches the one from the original request. That however ties the oracle to the suggest box with a 1:1 relationship (if that's a problem, you could have a suggest oracle that does this filtering, and delegates to a shared oracle).

If not, is there a way to wait for at least 3 letters before the suggestions mechanism is triggered ?

Just do that in your suggest oracle, returning an empty list of suggestions for request strings that are too short.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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