【发布时间】:2018-12-07 13:36:38
【问题描述】:
我正在从服务器返回的对象的字段hhead 中搜索值yes:
Object.keys(this.data).forEach(key => {
if (this.data[key].hhead === 'yes') {
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);
}
}
});
这个脚本的问题是if 和else 都是真的。所以这两个脚本都会运行。
原因是,在第一个条件下,一旦找到yes 值,条件就变为真。
第二个,一旦找到no,它就会运行。
数组是这样的:
所以我需要的是如果一个数组在所有行中只包含no,则运行else 部分。如果它发现至少 yes 运行第一个条件。
【问题讨论】:
标签: arrays angular object angular7