[英]Auto Complete source response
這是我第一次來到這個平台。
我需要一點幫助,我嘗試修改此代碼以集成我的數據,但我做不到。
這是我的返回 json 和我的 JS
傑森
{"data":[{"id":6,"name":"City1","lat":"56.401488","lon":"6.590949"},{"id":7,"name":"City2","lat":"56.373565","lon":"6.477635"}]}
JS
if( $("input.search_location_js").length > 0 ) {
jQuery('input.search_location_js').autocomplete( {
source: function ( request, response ) {
jQuery.get( 'https://URL.com/data/public/items/city', {
q: request.term,
limit:'4',
}, function( result ) {
if ( !result.length ) {
response( [ {
value: 'nc',
latitude:'56.3667',
longitude:'56.4833',
label: 'nc'
}]
);
return;
}
response( result.map( function ( place ) {
return {
label: place.data[*][*].nom,
latitude: place.data[*][*].lat,
longitude: place.data[*][*].lon,
value: place.data[*][*].nom,
};
} ) );
}, 'json' );
},
select: function ( event, ui ) {
$('input[name="lat"]').val(ui.item.latitude);
$('input[name="lng"]').val(ui.item.longitude);
if(is_halfmap) {
var current_page = 0;
dps_search_on_change(current_page);
}
}
});
}
place.data[ ][ ].name 我想在json中檢索城市的名稱但是上面的路徑不起作用
我還測試了 .data.name 和 .data[i].name ...
ps:我的問題出在這部分代碼中
response( result.map( function ( place ) {
return {
label: place.data[*][*].nom,
latitude: place.data[*][*].lat,
longitude: place.data[*][*].lon,
value: place.data[*][*].nom,
};
} )
我還在找,還是找不到。 我認為它是指向對象和數組的鏈接,我找不到任何有效的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.