javascript - 在整个回调函数中保留变量值
问题描述
我有这个功能:
var contor = 0;
function processImobs(){
for( var i = 0; i < availableImobs.length; ++i){
processEachImob(availableImobs[i]);
}
}
在我的 processEachImob 函数中,我从谷歌地图调用了附近的搜索方法:
service = new google.maps.places.PlacesService(map);
service.nearbySearch({
location: new google.maps.LatLng(imob[0], imob[1]),
radius: 500,
type: ['pharmacy']
},function callBack(results, status){
//cate tipuri de places primesc
markersP= [];
if (status == google.maps.places.PlacesServiceStatus.OK){
for (var i = 0; i < results.length; i++) {
createPharmaciesMarker(results[i]);
}
//console.log(markersP.length + " " +imob[0]);
if( markersP.length !=0){
for(var i=0; i < markersP.length; ++i){
++contor;
var latLng = [markersP[i].position.lat(), markersP[i].position.lng()];
queue.add(imob, latLng, 'pharmacy');
}
}
}
});
“contor”是一个全局变量,我想从 processImobs() 访问它,但它的值仍然是 0,因为我猜它不会在整个回调中保留?有没有办法解决这个问题?
解决方案
推荐阅读
- python - Python中数据框的Json值数组
- python - 跨存储库重构导入语句
- amazon-web-services - Cloudfront 为备用域名返回 502
- docker - 无需执行 docker push 即可将文件复制到 docker 容器/映像
- c# - 未在可观察集合中正确添加元素,来自过去活动的 id 未正确传递
- isabelle - 伊莎贝尔组合证明凯莱公式
- python - fbProphet 的表现比平均水平差
- google-cloud-firestore - 如何为不同的集合设置不同的规则
- mysql - 如何显示我的表中不存在的数据的计数(*)我的 mysql
- audio - 您可以使用 ffmpeg 在特定时间将一个音频文件插入另一个音频文件吗?