Jquery 在大型数组上自动完成

发布于 2024-09-26 08:35:23 字数 271 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

屋檐 2024-10-03 08:35:23

您可以使用 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.

甲如呢乙后呢 2024-10-03 08:35:23

我会像 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.

书信已泛黄 2024-10-03 08:35:23

您是否使用标准 jQuery 自动完成插件?如果是这样,我不熟悉您使用的选项参数“source”。

该插件的正确语法是:autocomplete( url or data, [options] )。听起来你的版本适用于“源”选项参数,(尽管浏览器崩溃)所以我很困惑。如果浏览器崩溃,我预计问题与 javascript 有关。

我建议尝试:

$('whatever').autocomplete(array1,{
    matchContains: true, 
    minLength: 3, 
    delay: 700,  
    max: 10, 
    highlight: true 
});

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 
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文