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

时间:2012-05-30 12:07:27

标签: twitter-bootstrap typeahead

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

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

提前致谢:)

1 个答案:

答案 0 :(得分:7)

matchertypeahead函数参数中的一个选项。来自文档:

  

用于确定查询是否与项匹配的方法。接受一个   单个参数,用于测试查询的项目。访问   使用this.query进行当前查询。如果查询是a,则返回布尔值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
    }
})

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