![](/img/trans.png)
[英]jQuery deferred : use to delay return of function until async call within function complete + get return value
[英]Return value that is within a then async function
我不知道如何返回在第一個函數中找到的變量值的值,然后將它們與then()一起使用,如下所示。
async escribeSolido(contenido: any) {
const ancho = 300;
...
contenido.map(async (item: any) => {
let image = new Jimp(ancho, alto, item.color, (err: any, imagen: any) => {
if (err) {
throw err;
}
});
Jimp.loadFont(Jimp.FONT_SANS_32_BLACK)
.then(font => {
...
return image;
})
.then(async(image) => {
let file = uuid()+'.png';
const path = __dirname +'/public/'+file;
values = await cloudinary.v2.uploader.upload(path, {folder: 'anuncios_basicos'});
/*Return this values*/
console.log('Values -----: ', values);
})
})
});
//return values;
}
我的其他功能
await abService.escribeSolido(contenido)
.then((value: any) => console.log('Values: ', value)) // undefined
.catch((err: any) => console.log(err))
我的結果
Values: undefined
POST /api/anuncio 200 75.451 ms - 463
Values -----: { public_id: 'anuncios_basicos/qnp6s1ptxwzxc0rrwzhp',
....
url:
'http://res.cloudinary.com/dshskwox0/image/upload/v1554922819/anuncios_basicos/qnp6s1ptxwzxc0rrwzhp.png',
secure_url:
'https://res.cloudinary.com/dshskwox0/image/upload/v1554922819/anuncios_basicos/qnp6s1ptxwzxc0rrwzhp.png',
original_filename: 'e59df336-eba1-4b17-9101-fe6bfeed07dc' }
您需要返回console.log語句所在的值。 這會將值返回到由該數組構造的數組。 要從escribeSolido函數返回值數組,只需將return放在地圖的前面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.