我有一个输入框来搜索产品。 它使用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.
更多推荐
发布评论