gpt4 book ai didi

javascript - jQuery 自动完成显示相同的结果

转载 作者:行者123 更新时间:2023-12-03 03:57:02 24 4
gpt4 key购买 nike

我正在使用 jQuery 对大量数据进行自动完成。我的代码在此片段中:

$( function() {
$( ".postal-code-autocomplete" ).autocomplete({
source: postal_codes,
minLength: 3,
});
});

但是,当自动完成完成并且我返回结果时,它仍然显示许多具有相同值的记录,即我正在寻找的记录,如图所示:enter image description here

我希望在找到我的结果时不会出现具有相同结果的下拉列表。

非常感谢!

编辑:如果我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"…]

最佳答案

有一个非常方便的 jQuery 函数 .uniqueSort(),您可以调用数组来对其进行排序并删除重复元素。

尝试设置来源:$.uniqueSort(postal_codes)

关于javascript - jQuery 自动完成显示相同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44900079/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com