【发布时间】:2018-06-21 02:29:59
【问题描述】:
我想创建一个返回 true 的函数(每个对象应该至少有一个 isValid:true)否则返回 false。
const Items = [{
parentValidators: [{
isValid: true
}, {
isValid: false
}, {
isValid: false
}]
},
{
parentValidators: [{
isValid: true
}, {
isValid: false
}, {
isValid: false
}]
}
]
// i tried :
validateSection() {
Items.map(item => {
if (item.parentValidators) {
const logs = item.parentValidators;
return logs.map(l => {
return l.isValid ? true : l.isValid;
});
}
}).map((i, indx, arr) => {
let count = 0;
if (i.includes('true')) {
count++;
}
return count === array.length ? true : false;
})
}
【问题讨论】:
标签: javascript jquery reactjs ecmascript-6