Jquery autocomplete on large array
I am using Jquery autocomplete with local array of size ~5000, every word is ~10 chars. I am initializing the object like this:
.autocomplete({matchContains: true, minLength: 3, delay: 700, source: array1, max: 10, highligh开发者_开发知识库t: true })
The problem is, that when I start to type, it takes a lot of time (sometime crashes the browser) until the result is displayed.
What can I do?
Thanks
You could use AJAX to fetch the array instead of putting it into the HTML, increase the delay and the required minLength
before querying the server in order to reduce the matches.
I would do like Darin Dimitrov said, but I would also do a .Take(10) (or some arbitrary number that sounds good to you) in a quick linq statement on the server side. This would lessen the result set and would still become more accurate as the user continues to type.
Are you using the standard jQuery autocomplete plugin? If so, I'm unfamiliar with the option parameter "source" that you used.
The proper syntax for that plugin is: autocomplete( url or data, [options] )
. It sounds like your version works with the 'source' option parameter,(although while crashing the browser) so I'm confused. If the browser is crashing, I'd expect the problem to be related to the javascript.
I recommend trying:
$('whatever').autocomplete(array1,{
matchContains: true,
minLength: 3,
delay: 700,
max: 10,
highlight: true
});
精彩评论