-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
problem with source async #1185
Comments
Hmm, I'm not sure what's causing your problem. Here's an example I just whipped up that should be functionally equivalent to your code. It works as expected. Can you test your code in an incognito window? Just to make sure there's nothing goofy going on with caching. Also, if you could point me towards a page that demonstrates your problem, I can help debug. |
I tested in incognito window it doesn't work. And I look at the source code of async function source code in typeahead.bundle.js. I think it is this line cause the problem. When I putted it after function async(suggestions) {
suggestions = suggestions || [];
if (!canceled && rendered < that.limit) {
that.cancel = $.noop;
rendered += suggestions.length;
that._append(query, suggestions.slice(0, that.limit - rendered));
that.async && that.trigger("asyncReceived", query);
}
} |
Yeah... I'm not sure why that line of code exists. I'll get it fixed, thanks for the report and thanks for digging into the problem. Very helpful. |
Posted a PR with a fix, see #1200. Here's a version of typeahead.bundle.js with the fix in case you want to try it out before it is released. |
Ok, thanks |
+1! The patch works like a charm! Can you please release it? |
Release please! |
Can confirm this is a problem. It's exacerbated when you only use async and your remote returns exactly limit results. In this case rendered - limit = 0, so (0,0) gets passed to suggestions.slice |
For what it's worth, changing it this way makes typeahead.bundle.js |
Fixed by #1212 |
Is it just me who has a problem with this fix? Whenever
I don't know if I'm doing something wrong but for what it's worth, here's the work around I implemented: function async(suggestions) {
var howMany;
suggestions = suggestions || [];
if (!canceled && rendered < that.limit) {
that.cancel = $.noop;
rendered += suggestions.length;
howMany = (rendered <= that.limit) ? rendered : that.limit - rendered;
that._append(query, suggestions.slice(0, howMany));
that.async && that.trigger("asyncReceived", query);
}
} |
@sebsonic , I believe that's the intended behavior--limit is the total number of suggestions to render from all sources combined. |
oh my god thank you guys so much for this fix. I was tearing my hairout with this one. |
+1 I also am experiencing this problem, and had tracked down the problematic code. Great to see there's a fix! |
+1 for pushing this fix. I also spent over an hour digging into the source of 0.11.1 and came to the same conclusion that the "rendered +=" line needs to be moved down. |
Struggled with this problem for a long time today. Moving the line seems to fix it. How come it isn't being fixed in the release? |
Problem:
The ajax url will return a list of data of length 7, however, the suggestions only render the first 3 results.
Can anyone gives a example about how to use the async in source.
The text was updated successfully, but these errors were encountered: