我目前使用一个INPUT字段来触发jQuery UI自动完成,它从Geonames中提取数据。
$( "#city_state_country" ).autocomplete({
source: function( request, response ) {
$.ajax({
url: "http://ws.geonames.org/searchJSON",
dataType: "jsonp",
data: {
featureClass: "P",
style: "full",
maxRows: 6,
name_startsWith: request.term
},
success: function( data ) {
response( $.map( data.geonames, function( item ) {
return {
label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
value: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
}
}));
}
});
},
minLength: 3,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.label :
"Nothing selected, input was " + this.value);
},
open: function() {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
});
所以如果我开始键入"Bosto"
它为我提供了
Boston, Massachusetts, United States
但是我想为城市、州和国家有单独的INPUT字段——并且每个字段都有自动完成连接到Geonames,分别只返回城市、州和国家的建议。
所以打字:
"Bost" in the city INPUT would provide "Boston".
"Massa" in the state INPUT would provide "Massachusetts".
"United St" in the state INPUT would provide "United States".
这可能吗?
我已经尝试过将name_startsWith
更改为其他选项,但没有得到我所期望的。
根据文档http://www.geonames.org/export/web-services.html,您不能
您可以使用以下URL来完成此操作-例如:api.geonames.org/postalCodeSearchJSON?placename_startsWith=dehi&country=LK&username=demo
它将生成您输入的结果