我有一个 JSON 数组,如下所示:
[{"country":"FR","id":2,"latitude":-34.27175846153846,"longitude":54.16125384615385,"postcode":"00000","region1":"DOM-TOM","region2":"Terres australes et antarctiques","region3":"Crozet","region4":"","version":null},{"country":"FR","id":3,"latitude":46.203635000000006,"longitude":5.20772,"postcode":"01000","region1":"Rhône-Alpes","region2":"Ain","region3":"Bourg-en-Bresse","region4":"Bourg-en-Bresse","version":null}, ...
我正在尝试将此数组用作 JQuery 自动完成的源。这是我尝试的:
$(function() {
$("#postcode").autocomplete({
source : function(request, response) {
var firstChars = $("#postcode").attr("value");
$.getJSON("/kadjoukor/geolocations", {
postcodeFirstChars : firstChars
}, function(data) {
console.log(data.postcode);
response(data.postcode);
});
},
minLength : 3,
});
});
这是html:
<input type="text" name="member.geolocation.postcode" value="" id="postcode" placeholder="Code postal" />
我想显示这个 JSon 数组中的邮政编码变量。有人可以帮忙吗?