我链接了一系列的Promises,以便与数据库一起使用。从第一个Promise中,我检索了一个对象数组。在第二个Promise中,我为每个对象生成一个Promise。然后,我过滤结果。这是一个代码示例:
db.getUser(user)
.then(user=> Promise.all(
user.shirts.map(userShirt => db.getShirt(shirt.id))
) as Promise<IShirt[]>)
.then(shirts => {
shirts = shirts.filter(shirt => shirt.color === 'blue');
console.log(shirts);
})
.catch(err => {
console.log(err);
});
这是我的代码的简化示例。问题出在过滤操作中,我检索了一个0长度的数组。任何的想法?