例如,以下函数循环遍历包含输入字段名称和错误的数组。它通过检查验证字段的名称,然后将错误信息推送到无效的字段数组来完成此操作。
简短点说并写成更好:
addInvalidField (field, message) {
const foundField = this.invalidFields.find(value => {
return value.name === field.name
})
const errors = foundField.errors
if (!errors.some(error => error.name === message)) {
errors.push({ name: message, message })
}
},
还是更具体地这样?
addInvalidField (validatingField, message) {
const foundField = this.invalidFields.find(invalidField => {
return validatingField.name === invalidField.name
})
if (!foundField.errors.some(foundFieldError => foundFieldError.name === message)) {
fouldField.errors.push({ name: message, message })
}
},