var events = <?php echo $sf_data->getRaw('jsonData'); ?>;//some perfecly fine json
var l开发者_开发百科ocations = new Array();
var geocoder = new google.maps.Geocoder();
$(events).each(function(i,e){
geocoder.geocode({address: e.place},function(results,statusCode){
locations[e.id] = results[0].geometry.location;
})
})
alert(locations.length);
Okay, the question is easy. How do i modify the locations array inside of closure? The alert shows 0.
The alert shows 0 because you modify locations
asynchronously. Anonymous function where you modify locations
will be called later then you show alert.
精彩评论