因此,我有两个数组:clientFeatures(包含每个索引中每个clientFeature的ID)和featureLocalIds(包含每个索引中的ID),而且我必须在异步函数中映射每个值。我知道我们可以使用Promise.all(mapFunctionWithAsync)映射异步函数,但是如何完成双重映射?我的代码如下:
基本上,我必须使用ClientFeature模型的“ id”字段中的clientFeatures.id值和ClientFeature模型的“ featureId”字段中的featureLocalIds值来更新ClientFeature,并且必须在同一时间执行!我尝试了下面的代码,但只是将一个featureLocalId添加到多个clientFeatureIds
let clientFeatures = await ClientFeature.query("clientId")
.eq(client.id)
.exec();
let featureLocalIds = agreementFeatures.clientFeatureId;
var clientFeaturesNew = featureLocalIds.map(async item => {
let newClientFeatures = await Promise.all(
clientFeatures.map(async clientFeature => {
clientFeatureGen = await ClientFeature.update({
id: clientFeature.id,
clientId: client.id,
featureId: item,
enabled: true
});
return clientFeatureGen;
})
);
});