我使用此参数在不敏感的案例模式下进行我的bootstrap typeahead搜索.
matcher: function(item) {
return true
}
我喜欢输入口音,比如输入“e”搜索é,è,ë,ê等…但不适用于大写和小写=>输入“g”不会寻找“G”……
还有其他参数吗?
最佳答案 好的,这就是我使用Paul的解决方案所做的:
matcher: function(item) {
if (item.toLowerCase().indexOf(this.query.trim().toLowerCase()) != -1) {
return true;
}
if (item.toUpperCase().indexOf(this.query.trim().toUpperCase()) != -1) {
return true;
}
var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
query = query.replace(/a/ig, '[a\341\301\340\300\342\302\344\304]');
query = query.replace(/e/ig, '[e\351\311\350\310\352\312\353\313]');
query = query.replace(/i/ig, '[i\355\315\354\314\356\316\357\317]');
query = query.replace(/o/ig, '[o\363\323\362\322\364\324\366\326]');
query = query.replace(/u/ig, '[u\372\332\371\331\373\333\374\334]');
query = query.replace(/c/ig, '[c\347\307]');
if(item.toLowerCase().match(query.toLowerCase())){
return true;
}
}
有了这个,你有一个真正的不敏感的情况.我推出了主要的特殊字符.您可能希望为匹配添加额外的字符.