JQuery Autocomplete does not show all the results

允我心安 提交于 2019-12-13 08:10:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!