【问题标题】:Typeahead only showing the exact match. How can I show all the data that is returned from remote url.?Typeahead 仅显示完全匹配。如何显示从远程 url 返回的所有数据。?
【发布时间】:2015-12-23 17:48:41
【问题描述】:

我遇到了一个问题,我想实现一个搜索,如果你用双引号(“”)键入字符串,它也必须工作。

示例:apple 和 "apple" 都必须返回相同的结果

当我调用后端时,两个搜索查询的调用都在重新调整相同的内容,但预输入会以某种方式过滤数据,并且在“apple”的情况下不会显示数据。

我尝试过使用 dropDownFilter 之类的过滤器,并通过将它们分配为 false 来过滤:

$('#searchInput').typeahead({ minLength: 1, order: "asc", delay: 500, 
                              dynamic: true, groupMaxItem: 6, highlight: false, 
                              hint: true, group: ["{{group}}, kind"], 
                              dropdownFilter: false,

但它不起作用,任何人都可以给我一些建议。

任何帮助将不胜感激!

【问题讨论】:

  • 能否在出现问题的地方包含一些代码?
  • $('#searchInput').typeahead({ minLength: 1, order: "asc", delay: 500, dynamic:true, groupMaxItem: 6, highlight:false, hint: true, group : ["{{group}}, kind"], dropdownFilter: false}) 我试过了!
  • 如何填充数据源?
  • 我在填充数据的源中使用 url。
  • 您可以提供自己的matcher 函数吗?

标签: javascript typeahead.js typeahead bootstrap-typeahead twitter-typeahead


【解决方案1】:

尝试提供您自己的匹配器功能。大致如下:

$('.typeahead').typeahead({source:myarray, matcher: function(item){
    // the regular expression will (optionally) consider double-quotes
    var reg = new RegExp('"?'+this.query+'"?');

    if( item.match(reg) ){
        return true;
    }else{
        return false;
    }
 }});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-15
    • 2019-05-06
    • 2023-01-24
    • 1970-01-01
    相关资源
    最近更新 更多