簡體   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