jQuery UI 自动完成的自定义搜索功能

发布于 2024-09-18 13:21:23 字数 238 浏览 2 评论 0原文

我正在使用 jQuery UI 自动完成

有没有办法覆盖其默认搜索算法?

我想要进行的更改是:

  • 优先考虑建议结果顶部以搜索词开头的单词。
  • 最多返回 5 个结果(而不是默认行为,即返回所有匹配结果,可能会创建一个非常高的下拉框)。

I'm using jQuery UI Autocomplete.

Is there a way to override its default search algorithm?

The changes I want to make are:

  • Prioritize words that start with the search term at the top of the suggested results.
  • Return a maximum of 5 results (instead of the default behavior, which is to return all matching results, potentially creating a really tall dropdown box).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

仙女山的月亮 2024-09-25 13:21:23

通常,这一切都应该在后端完成。您的服务器端脚本定义返回结果的顺序和数量。

或者(如果后端不在您的控制之下),您可以将函数指定为 source 属性。在此功能中,您可以查询后端并以您想要的方式处理结果。例如,这是一个例子
http://jqueryui.com/demos/autocomplete/#multiple-remote

Normally, it all should be done in back-end. Your server-side script defines in what order and how many results will be returned.

Alternatively (if back-end is not under your control), you can specify function as source attribute. In this function you can query back-end and process results in whatever way your want. E.g., here's an example
http://jqueryui.com/demos/autocomplete/#multiple-remote

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