繁体   English   中英

我有一组对象要检查,主要是真的只有一次在复选框上,否则显示警报

[英]I have a array of objects to check from that primary is true is only one time on the checkbox otherwise show alert

我有一组对象要检查,主要是真的只有一次在复选框上,否则显示警报见下图:-

主要不检查第二次检查

 <mat-checkbox class="example-margin" [(ngModel)]="primary" formControlName="primary"> Make this primary </mat-checkbox>

在这个 object 数组中,有 2 个 primary = true

假设您的数组是data

let primaryGuys = data.filter(person => person.primary === true);
if(primaryGuys >1) {
   alert('HEY!')
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM