我正在使用jQuery对大量数据进行自动完成。我的代码在此代码段中:
$( function() {
$( ".postal-code-autocomplete" ).autocomplete({
source: postal_codes,
minLength: 3,
});
});
然而,当完成自动完成并且我的结果返回时,它仍会显示一些具有相同值的记录,即我要查找的记录,如图所示:
我希望这个下拉列表具有相同的结果,当找到我的结果时不会出现。
非常感谢!
编辑:如果我console.log(postal_codes)
我得到以下结果
(54767) ["15354", "13341", "13675", "13451", "17455", "15127", "15562", "14561", "13671", "12241", "13451", "15341", "13561", "17341", "17343", "12244", "15349", "13343", "16452", "16672", "16673", "15235", "16233", "15354", "16777", "14122", "13122", "13231", "13121", "13123", "17778", "17676", "13451", "14562", "14123", "15124", "15127", "14671", "15236", "17121", "14342", "15451", "12134", "12132", "15121", "15237", "12462", "15232", "15561", "15562", "15452", "12351", "15341", "13561", "12244", "13341", "16452", "13671", "15235", "16233", "16777", "15772", "14122", "13122", "13451", "14562", "14123", "15124", "15127", "14231", "15236", "14342", "15451", "17563", "15236", "12136", "12461", "13231", "15121", "15237", "15452", "13451", "16777", "13342", "16122", "17121", "16342", "16777", "16777", "15773", "16777", "15773", "15772", "13122", "10431", "10432", "10433", "10434", "11251", "16452"…]
答案 0 :(得分:1)
有一个非常方便的jQuery函数.uniqueSort(),你可以调用它来对它进行排序并删除重复的元素。
尝试设置source: $.uniqueSort(postal_codes)