大家好我有下面的对象结构,我正在尝试使用解构技术获取所有内部对象的名称但无法做到这一点,下面是对象结构
{
massingType {
id
name
}
ashraeClimateZone {
id
name
}
sourceOfData {
id
name
}
.....
}
我正在做如下的解构
constructionSetData.constructionSets.forEach(item => {
if (
item.ashraeClimateZone?.id === ashraeClimateZoneId &&
item.massingType?.id === massingTypeId &&
item.sourceOfData?.id === energyCodeId
) {
matchedConstructionDataSet.push(item.name);
const { sourceOfData: name, massingType: name, ashraeClimateZone: name } = item; // getting error here Identifier 'name' has already been declared
}
});
return matchedConstructionDataSet.length
? `${matchedConstructionDataSet.join(', ')}` // here i need to use above names coming from three inner objects
: 'No construction set found with the current criteria';
任何人都可以让我知道我怎样才能实现这个解决方案,非常感谢!
呼啦一阵风
相关分类