jQuery UI 自动完成的自定义搜索功能
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,这一切都应该在后端完成。您的服务器端脚本定义返回结果的顺序和数量。
或者(如果后端不在您的控制之下),您可以将函数指定为
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 examplehttp://jqueryui.com/demos/autocomplete/#multiple-remote