在theNowDetailList数组中为每个对象的productList添加新对象
您可以使用forEach循环遍历theNowDetailList数组,然后在每个对象的productList中添加一个新的对象。可以使用Object.assign方法将外层对象的内容复制到新的对象中,并增加所需的属性。
以下是一个示例代码:
theNowDetailList.forEach(function(detail) {
var newProduct = Object.assign({}, detail, {
'theNowDetailId': detail.theNowDetailId,
'theNowId': detail.theNowId,
'productId': null,
'isEdit': true,
'classeIds': [],
'classes': '',
'variety': detail.variety,
'productName': detail.productName,
'specification': detail.specification,
'property': detail.property,
'weight': detail.weight,
'surface': detail.surface,
'tectorial': detail.tectorial,
'priceUnit': '元/kg',
'amountUnit': 'kg'
});
detail.productList.push(newProduct);
});
这样,theNowDetailList数组中的每个对象的productList中都会添加一个新的对象,该对象包含外层对象的内容,并添加了额外的属性。
原文地址: https://www.cveoy.top/t/topic/qmNF 著作权归作者所有。请勿转载和采集!