Typeahead:显示所有结果而不是精确的字符串匹配(Typeahead: show ALL results instead of exact string matches)

编程入门 行业动态 更新时间:2024-10-26 08:29:30
Typeahead:显示所有结果而不是精确的字符串匹配(Typeahead: show ALL results instead of exact string matches)

我有一个输入框来搜索产品。 它使用typeahead来获取和显示返回的数据。

当ajax响应包含的结果与我的输入值不完全匹配时,会出现问题。 例如:

input query = "daffalgane" JSON data result is = {products: { id:100, label: "dafalgan 500" }, { id:101, label: "dafalgan 750mg" }, { id:500, label: "daffalgane 600 mg" }, }

Typeahead仅显示id为500的那个,因为它具有精确(部分)字符串匹配。

为什么没有显示其他结果? 对我来说更有意义的是,typehead只显示返回的数据集。

作为参考,这是用于输入框的配置:

$('#suggestions').typeahead({ minLength: 1, maxItem: 10, hint: false, highlight: false, emptyTemplate: 'NO RESULTS', source:{ products: { display: "label", href: baseurl+'{{slug}}', url: [{ type: "POST", url: baseurl+'/suggest', data: { for: "{{query}}".trim() }, }, "data.products"], }, }});

I have an input box to search for products. It uses typeahead to fetch and display the returned data.

A problem arises when the ajax response contains results that does not exactly match my input value. For example:

input query = "daffalgane" JSON data result is = {products: { id:100, label: "dafalgan 500" }, { id:101, label: "dafalgan 750mg" }, { id:500, label: "daffalgane 600 mg" }, }

Typeahead only displays the one with id:500, since it has an exact(part of the) string match.

Why are the other results not displayed? It would make more sense to me that typehead would just display the returned dataset.

For reference, this is the config used for the input box:

$('#suggestions').typeahead({ minLength: 1, maxItem: 10, hint: false, highlight: false, emptyTemplate: 'NO RESULTS', source:{ products: { display: "label", href: baseurl+'{{slug}}', url: [{ type: "POST", url: baseurl+'/suggest', data: { for: "{{query}}".trim() }, }, "data.products"], }, }});

最满意答案

我通过升级到typeahead版本2.3.4( http://www.runningcoder.org/jquerytypeahead/ )并将filter参数设置为false来解决此问题。

这可以防止对typeahead完成的结果进行过滤,只显示源。

I fixed this by upgrading to typeahead version 2.3.4 (http://www.runningcoder.org/jquerytypeahead/) and setting the filter parameter to false.

This prevents the filtering on the results done by typeahead and just displays the source.

更多推荐

本文发布于:2023-08-04 23:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1424476.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   精确   而不是   Typeahead   show

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!