現在、単一のINPUTフィールドを使用して、GeonamesからデータをプルするjQueryUIオートコンプリートをトリガーしています。
$( "#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" );
}
});
だから私が「ボスト」とタイプし始めると
それは私に
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
他のオプションに変更してみましたが、期待したものが得られませんでした。