我正在尝试在我的母语(越南语)中使用带有声调标记的jquery-autocomplete。它能精确匹配一个单词。但是,我希望搜索功能忽略声调标记,即默认情况下,搜索“L?m”和"Lam“都会匹配”L?m“。
谢谢。
发布于 2013-04-10 18:52:27
我假设您对客户端数据使用自动完成。
有关替换拉丁字母上的变音符号的javascript代码,请参见this answer.
source option.side,check
下面是一个大纲(未经过测试),让您了解如何使用source函数:
// use the 'removeDiacritics' function from the quoted answer above
function removeDiacritics(str) {
...
}
var myData = ['aäa', 'bbb'];
$('input#autocomplete').autocomplete({
source: function(request, responseCallback){
// 'request' holds the value typed in the input,
// remove diacritics from this value, and build a regexp :
var reSearch = new RegExp( removeDiacritics(request) );
// build an array of matched values :
var result = [];
for (var i=0; i<myData.length; i++){
// for each search candidate, run it through removeDiacritics,
// and see if result macthes the (diacritics free) regexp :
if ( reSearch.match( removeDiacritics(myData[i]) ) ){
result.push(myData[i]);
}
}
// call the callback with this array :
responseCallback(result);
}
});https://stackoverflow.com/questions/15923497
复制相似问题