小写的jQuery自动完成搜索 [英] jquery autocomplete search by lowercase
本文介绍了小写的jQuery自动完成搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想工作的jquery自动完成插件小写。该阵列包括大写,小写的话。卜当我写在文本框中的文字,jQuery的应该转换为小写文本和转换阵列字小写然后匹配的话。
VAR名= {[
值:1,
标签:乔恩Kerer},
{
值:2,
标签:斯科特MART},
{
值:3,
标签:SEL HURGE}
];$(#myInput)。自动完成({
重点:......?
选择 : .... ?
资源 : ... ?
});
解决方案
您需要创建一个字符映射并做名字解析一些。这仅仅是一些字符的起动器列表。你可以尝试一些全球化库找到了一套完整的
DEMO: http://jsfiddle.net/uQK5s/
VAR accentMap = {
A:一,
ö:O,
S:S,
A:一
};
VAR规范化=功能(项){
VAR RET =;
对于(VAR I = 0; I< term.length;我++){
保留+ = accentMap [term.charAt(ⅰ)] || term.charAt(ⅰ);
}
返回RET;
};$(#测试)。自动完成({
来源:函数(请求,响应){
VAR匹配=新的RegExp($ ui.autocomplete.escapeRegex(request.term),I);
响应($。grep的(名称,功能(价值){
值= value.label || value.value ||值;
返回matcher.test(值)|| matcher.test(正常化(值));
}));
}
});
I wanna work jquery autocomplete plugin with lowercase. The array includes uppercase, lowercase words. Bu when I write text in textbox, the jquery should convert to lowercase that text and convert the array words to lowercase then match words.
var names = [{
value: "1",
label: "Jon Kerer"},
{
value: "2",
label: "Scott MART"},
{
value: "3",
label: "Sel HURGE"}
];
$("#myInput").autocomplete({
focus: ..... ?
select : .... ?
source : ... ?
});
解决方案
You will need to create a character map and do some parsing of the names. This is just a starter list of some characters. You could try some of the globalization libraries to locate a complete set
DEMO : http://jsfiddle.net/uQK5s/
var accentMap = {
"á": "a",
"ö": "o",
"Ş": "S",
"á": "a"
};
var normalize = function(term) {
var ret = "";
for (var i = 0; i < term.length; i++) {
ret += accentMap[term.charAt(i)] || term.charAt(i);
}
return ret;
};
$("#test").autocomplete({
source: function(request, response) {
var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
response($.grep(names, function(value) {
value = value.label || value.value || value;
return matcher.test(value) || matcher.test(normalize(value));
}));
}
});
这篇关于小写的jQuery自动完成搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文