如何使这个函数返回整个数组完成推动所有标记?* JSON完成后返回数组* *
function XTW_getLocations(data, div_id, map) {
var markers = [];
var marker;
var latLngBounds = new google.maps.LatLngBounds();
$(div_id).empty();
$.getJSON('GetLocations', "country=" + data.id,
function(data){
$.each(data, function(index, data) {
latLngBounds.extend(new google.maps.LatLng(data.location.latitude, data.location.longitude));
$(div_id).append(new Option(data.name, data.id));
marker = createMarker(data, icon, html, map);
markers.push(marker);
});
map.fitBounds(latLngBounds);
});
return markers;
}
而我可以在那里返回标记呢? – 2010-09-13 12:26:12
不幸的是,没有......你永远无法将标记返回到任何地方,但是你可以处理回调中的数据,或者如果你想重用它,而不是匿名函数使用命名函数。 – 2010-09-13 12:35:12
我很快尝试了它,并返回XTW_getLocations(x,x,x,function(markers){return markers;})* SEEMS *。但是,情况并非如此?这只是运气? – 2010-09-13 12:36:56