【发布时间】:2020-09-01 02:02:23
【问题描述】:
这是需求代码,dataJoin(像多条记录一样的对象数组)结果,有json值。这些 json 值,必须找到相关项。因此,用于语句,用于查找 json 值。收集 json 值,使用 userService 函数,并获取数据,然后将这些数据合并到父数据。它不工作。因为,在完成for循环语句之前,res.send("...")项已经执行,这是我的问题...
请任何人指导我...
谢谢
table1Obj
.findAll(
{
include: [
{
model: assocaitonTableObject,
required: false,
}
],
where: req.query,
})
.then((dataJoin) => {
for(element of dataJoin ) {
const arrayCollection = [];
let whereConstraint = {};
JSON.parse(element.joinedUsersList).forEach( async (ele) => {
arrayCollection.push(ele.userId);
});;
whereConstraint = {
id : {
[Op.in]: arrayCollection
}
}
const usesrListData = userService.customfindAll(whereConstraint);
element.userListData = usesrListData;
}
res.send({
status:200,
message:"OK",
data:dataJoin
});
})
.catch((err) => {
res.status(500).send({
status:500,
message:
err.message ,
});
});
【问题讨论】:
标签: sequelize.js findall