我认为你试图从错误的角度来解决这个问题。必须先扫描集合,然后运行代码:
var mached = this.data.every(t => t.hhead == 'yes'); //this will print true
Object.keys(this.data).forEach(key => {
if (mached) {
console.log('Yes '+(this.data[key].hhead === 'yes'))
this.snackBar.open('This household already have ' + this.data[key].far + ' ' + this.data[key].lar + ' (id: ' + this.data[key].iid + ' ) as a head of household', 'Close', {
panelClass: 'error'
});
} else {
console.log('No '+(this.data[key].hhead === 'no'))
if (data['age'] <= 17 && data['age'] < this.maxAge && (selectedFr == "Head Of Household")) {
let message = 'This individual is not the oldest in his family to be the head of household. Do you want to complete this action ?';
this.openDialog(message, updateType, ind_id, newSts, newMs, newFr, newHH, oldHH, missingData);
}
}
});