在回调函数中更改全局变量值

时间:2018-08-06 08:59:23

标签: node.js

我正在调用函数并将数据推入数组,但数组为空

property.forEach(function(proObj){
  var photo=[];
  proObj.photosId.forEach(function(Pid){
    fileUpload.fetchPhotoById(Pid,function(photoObj){
      photo.push(photoObj); //photo obj is added to photo Array
      console.log('source:-'+photoObj); // getting data correctly
    }) 
  })
  proObj.photos=photo;  
  console.log('Photo Array'+photo); // photo has default value means empty array
})

请帮助我任何人解决

0 个答案:

没有答案