const a = [
{
aa: '',
bb: null,
cc: null,
yesones: '',
dd: ' `请选择险`',
id: '18',
missingFields: 1,
yestwo: '',
type: '02',
},
{
aa: '',
bb: null,
cc: null,
yesones: '',
dd: ' `请选择`',
id: '18257705',
missingFields: 1,
yestwo: '',
type: '03',
},
{
aa: '',
bb: null,
cc: null,
yesones: '',
dd: ' `请选择`',
id: '1533281795',
missingFields: 1,
yestwo: '',
type: '',
}
]
当数据里的type等于02和03的时候必须校验yestwo和yesones是否填写,如果填写了返回了true 无填写返回false
解决方案
function checkData(data: any) {
return data.every((item: any) => {
if (['02', '03'].includes(item.type)) {
return item.yestwo&& item.yesones
}
return true
})
}
const result = checkData(a)
console.log(result, 'a')