所以,我知道這已經問過,我已經試過像.map
,(function(post){ async })(value)
其他答案,我仍然停留...的Javascript:對象的數組,每個對象改變值異步
所以,我有對象和數組的for循環:
var postsData = [{thumbnail: www.website.com/image.jpg}, {thumbnail: www.website.com/image.jpg}, {thumbnail... etc}];
for (let i = 0; i < 3; i++) {
let thumbnail = postsData[i].thumbnail;
Cloudinary.uploader.upload(thumbnail, function(result){
// not sure what to do here
// result comes back as an object, and I want to change each thumbnail in
// the postsData array to be result.public_id
}, {transformation:[{}]});
} // go through all the items in the array
// do something with "updated" postsData array
一個例子將真正幫助,因爲很明顯,得到的值更改涉及到一些異步函數。
你'postsData'是無效的 - 也許這是一個起點(值應弦) –