将Bootstrap Typeahead匹配器设置为不区分大小写

The*_*est 6 typeahead twitter-bootstrap

我需要在Twitter Bootstrap Typeahead插件中设置匹配器,以区分大小写.Bootstrap文档指定需要将函数传递给typeahead选项,但不指定该函数应该是什么.

如果有人能告诉我怎么做,我将不胜感激.

提前致谢 :)

ken*_*ken 7

matchertypeahead函数参数中的一个选项.从文档:

用于确定查询是否与项匹配的方法.接受单个参数,即用于测试查询的项目.使用this.query访问当前查询.如果查询匹配,则返回布尔值true.

所以,它看起来像这样:

$('.typeahead').typeahead({
    matcher: function(item) {
        // Here, the item variable is the item to check for matching.
        // Use this.query to get the current query.
        // return true to signify that the item was matched.
        return true
    }
})
Run Code Online (Sandbox Code Playgroud)

它还在文档中说这个回调的默认行为是case insensitive匹配器.因此,您的需求应该是开箱即用的.

  • 有没有办法让匹配器工作?我认为它在Typeahead中被删除了. (2认同)