我有这个代码
function imagenesIn(errU,errores)
{
if(errU) throw errU;
var directorios=new Array();
var origenDir='';
var destinoDir='';
if(errores=='')
{
if(campos.img instanceof Array)
{
for(file in campos.img)
{
origenDir='';
destinoDir='';
origenDir=campos.img[file].path;
destinoDir='/uploads/publish/alquiler/'+req.session.passport.user+campos.img[file].name;
fs.rename(origenDir,process.cwd()+'/public'+destinoDir,function(err)
{
if (err) throw err;
directorios.push(destinoDir);
console.dir(directorios)
})
}
}
}else{
res.send(errores)
}
return directorios;
},
我想在directios中获取req.files.img中campos.img中所有文件内容的命运数组
但是当我在控制台中打印时发生了
"img": [
"/uploads/publish/alquiler/andres@hotmail.comTulips.jpg",
"/uploads/publish/alquiler/andres@hotmail.comTulips.jpg"
],
我试图得到这个结果
"img": [
"/uploads/publish/alquiler/andres@hotmail.comTulips.jpg", //first img
"/uploads/publish/alquiler/andres@hotmail.flowers.jpg"//second img
],
为什么 .push() 方法只放第一个图像目录而不放第二个???我想念什么???
tnx