问题
I am facing the below issue all day and would appreciate any advice.
I am writing JQuery autocomplete and it shows only partial results but not all the results from arraylist.
When I debug in customFilter function, I see array
contains expected string in each row and term
has the correct input data from textbox.
function customFilter(array, terms) {
arrayOfTerms = terms.split(" ");
var term = $.map(arrayOfTerms, function (tm) {
return $.ui.autocomplete.escapeRegex(tm);
}).join('|');
var matcher = new RegExp("\\b" + term, "i");
return $.grep(array, function (value) {
return matcher.test(value.label || value.value || value);
});
};
$( "#frmCode" ).autocomplete({
multiple: true,
mustMatch: false,
minLength: 2,
source: function (request, response) {
response(customFilter(
availableCode, request.term));
}
});
I tried
var a = $.grep(autoData, function(value){
var matcher = new RegExp("\\b" + term, "i");
return matcher.test(term);
});
but it did not work either. May I know what is causing this problem?
回答1:
I changed
var matcher = new RegExp("\\b" + term, "i");
to
var matcher = new RegExp("" + term, "i");
and it is working now.
console.log("result - " + matcher.test(value.label || value.value || value));
console.log("value - " + value)
shows expected result as verification as well.
来源:https://stackoverflow.com/questions/45090558/jquery-autocomplete-does-not-show-all-the-results