新手编码器在这里。我有一个jQuery自动完成搜索栏,通过本地json数组搜索。当找不到匹配项时,我想返回一个字符串,表示“找不到”。jQuery UI自动完成:当没有搜索匹配发生时返回“没有找到”
我已经试过if语句里面$ .grep但至今没有奏效:
$("#div_name").autocomplete({
appendTo: ".custom-autocomplete",
source: function (request, response) {
var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
response($.grep(array, function(value) {
var not_found = 'Nothing found.';
if (matcher.test(value.value).length && matcher.test(value.nickname).length == 0) {
return not_found;
}
else {
return matcher.test(value.value)
|| matcher.test(value.nickname);
}
}));
},
感谢您的帮助! :)
想知道这一点。 – Koraktor 2011-03-21 07:19:48