我有以下输入:
schema: [{
fields: [{
name: 'name',
type: 'text',
col: 10,
value: ''
}, {
name: 'description',
type: 'text',
col: 2,
value: ''
}]
}, {
fields: [{
name: 'password',
type: 'text',
col: 8,
value: ''
}, {
name: 'confirmPassword',
type: 'textarea',
col: 4,
value: ''
}]
}],
我将嵌套数组对象的values
设置为以下内容:
updateField (name, value) {
this.schema.forEach((formGroup, index) => {
formGroup.fields.forEach(field => {
if (field.name === name) field.value = value
})
})
},
有没有一种方法可以避免使用两个嵌套的 forEach
?(不使用任何类库,如 Lodash?)