我目前正在尝试创建一个在我的数据库中搜索然后向前端返回响应的数组,但该数组始终返回 null,有没有办法阻止响应在 map 函数完成之前进行?
我的代码:
const result = await Database.raw(sqlResult)
const data = await result.rows.map((element, index) => {
this.getNomFun(result.rows[index].numcad)
.then((response) => {
const dataFun = response.toJSON()
return {
numcad: dataFun[0].numcad,
nomfun: dataFun[0].nomfun,
titred: dataFun[0].titred,
numcpf: dataFun[0].numcpf,
numcid: dataFun[0].numcid,
datnas: dataFun[0].datnas,
codccu: dataFun[0].codccu,
nomloc: dataFun[0].nomloc,
sms_documents_id: result.rows[index].sms_documents_id,
register_date: result.rows[index].register_date,
expiration_date: result.rows[index].expiration_date,
name: result.rows[index].name,
description: result.rows[index].description,
time_period: result.rows[index].time_period,
}
}).catch((err) => console.log(`err ${err}`))
})
return data