2 回答

TA貢獻1810條經驗 獲得超4個贊
好的。嘗試這個。將 lookup.js 更改為以下內容:
let options = {
? ? minCharNumber: 3,
? ? url: function (phrase) {
? ? ? ? return "https://nominatim.openstreetmap.org/search?q=" + $("#prova").val() + "&format=json";
? ? },
? ? getValue: "display_name",
? ? list: {
? ? ? ? match: {
? ? ? ? ? ? enabled: true
? ? ? ? }
? ? }
};
$("#prova").easyAutocomplete(options);
現在應該按照你想要的方式工作。如果對您有幫助,請點擊向上箭頭找到答案。這有助于我的排名。此外,如果它已為您解決,請單擊“這解決了我的問題”。

TA貢獻1810條經驗 獲得超4個贊
您可能缺少庫。我讓它與你的 JavaScript 一起工作:我創建了一個名為 lookup 的文件夾。在文件夾中我制作了兩個文件:
測試.html
查找.js
從http://easyautocomplete.com/files/EasyAutocomplete-1.3.5.zip的文件夾中下載并解壓縮 EasyAutocomplete-1.3.5 的代碼
測試.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lookup</title>
<link rel="stylesheet" href="EasyAutocomplete-1.3.5/easy-autocomplete.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<input type="text" id="prova" class="form-control search-slt" placeholder="Enter name1..." data-behavior="autocomplete" />
<script src="EasyAutocomplete-1.3.5/jquery.easy-autocomplete.min.js"></script>
<script src="lookup.js" defer></script>
</body>
</html>
查找.js
$(function () {
var minlength = 3;
$('#prova').keyup(function (e) {
var that = this,
value = $(this).val();
console.log("keyup");
if (value.length >= minlength) {
searchRequest = $.ajax({
type: "GET",
url: "https://nominatim.openstreetmap.org/search?q=" + $("#prova").val() + "&format=json",
//async: false,
success: function (results) {
console.log(results);
var aList = results;
var aOptions = [];
for (i = 0; i < aList.length; i++) {
//optKey = aList[i].geometry.coordinates[0] + ',' + aList[i].geometry.coordinates[1];
optLabel = aList[i].display_name;
aOptions.push(optLabel);
}
var options = {
data: aOptions
};
console.log(options);
$("#prova").easyAutocomplete(options);
}
});
}
});
});
就是這樣。應該工作正常。希望這對你有幫助。
添加回答
舉報