sequelize findAndAll() 获得一个数组,包含学生总数和相关信息的数组count和排序后的rows
await peoples = model.findAndCountAll({
where: {
loginName: name
},
order: updatedAt Desc'
})
对students.rows再异步插入成绩数据,
let result
Promise.all(students.rows.map((student) =>{
await score = model1.findById(student.id,{
attributes: ['score']
})
student.score = score
result.push(student)
}))
但是, 异步操作后获得的result已经不是排序的结果,会出现乱序,如何异步行为顺序执行?
笨办法,操作完成后补一次js排序 .sort(),抛砖引玉,楼下继续。