Jquery 在大型数组上自动完成
我正在使用 Jquery 自动完成功能,本地数组的大小约为 5000,每个单词约为 10 个字符。 我像这样初始化对象:
.autocomplete({matchContains: true, minLength: 3, delay: 700, source: array1, max: 10, highlight: true })
问题是,当我开始输入时,需要很长时间(有时会使浏览器崩溃)才能显示结果。
我能做些什么?
谢谢
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, highlight: 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 AJAX 来获取数组,而不是将其放入 HTML,在查询服务器之前增加延迟和所需的
minLength
以减少匹配。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.我会像 Darin Dimitrov 所说的那样,但我也会在服务器端的快速 linq 语句中执行 .Take(10) (或一些听起来不错的任意数字)。这将减少结果集,并且随着用户继续键入,结果集仍然会变得更加准确。
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.
您是否使用标准 jQuery 自动完成插件?如果是这样,我不熟悉您使用的选项参数“source”。
该插件的正确语法是:
autocomplete( url or data, [options] )
。听起来你的版本适用于“源”选项参数,(尽管浏览器崩溃)所以我很困惑。如果浏览器崩溃,我预计问题与 javascript 有关。我建议尝试:
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: