【问题标题】:How do i prevent bootstrap typeahead from double filtering non-matching results from ajax call如何防止 bootstrap typeahead 双重过滤来自 ajax 调用的不匹配结果
【发布时间】:2013-05-23 17:47:27
【问题描述】:

我正在使用带有 jQ​​uery ajax 的 bootstrap typeahead,我们将其称为 FILTER#1。就我而言,像“great tank”或“greattank”这样的 ajax 搜索都会产生“Great Tank”ajax 结果,但 typeahead 是第二次猜测我的结果并双重过滤掉(我们将调用 FILTER#2)第二个结果,因为空间。我的 ajax 结果也可能与输入的完全不同。我需要预先输入以相信所提供的结果是有效的,并且无论小写文本是否完全匹配都会显示它们。

我希望有以下行为:

  1. 如果结果中有匹配的词突出显示它
  2. 如果存在不匹配的单词,则将其显示为未突出显示,但将其保留在结果列表中,而不是将其过滤掉。

(1) 适用于 OOTB,但 (2) 是我正在寻找的缺失功能。如果我不能拥有 (1) 和 (2),我可以放弃 (1)。

这是一个小提琴示例:http://jsfiddle.net/PE9mN/

        $("#title2").typeahead({
        source: function( request, response ) {
              var mockResults2 = ["Great Tank War", 
                                  "Great Train Robbery",
                                  "other random result my server produced"];
            response(mockResults2); 
            // I expect this to display both items regardless of $("#title2").val() 
            // In my case, the server was smart enough to realize that 
            // "greattank" may match "great tank"
            // and it even added a 3rd value that I want to display.
            }
           }); 

谢谢。

【问题讨论】:

    标签: jquery twitter-bootstrap bootstrap-typeahead


    【解决方案1】:

    如果您将以下选项添加到预输入:

      matcher: function(item) {
          return true;
      }
    

    然后不会应用“第二个”过滤。

    【讨论】:

    • 我很幸运地找到了这个解决方案。谢谢
    【解决方案2】:

    您可以在初始化时执行此操作,如下所示

      //Typeahead autocomplete for address
        $('input.typeahead').typeahead({
            ajax: {
               .....
            },
            matcher: function () { return true; }
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-31
      • 1970-01-01
      • 2017-11-24
      • 2014-05-30
      • 1970-01-01
      • 2012-09-19
      • 1970-01-01
      相关资源
      最近更新 更多