猿问

在Angular 4中取消选中复选框后,如何从JSON数组中删除对象?

0:

CategoryId: "31b7a227-9fda-4d14-8e1f-1dee5beeccb4"

Code: "GMA0300"

Description: "PA-5215: Renamed"

Enabled: true

Favorite: false

Id: "26cfdb68-ef69-4df0-b4dc-5b9c6501b0dd"

InstrumentType: null

Moniker: "1GMA0300"

Name: "Celiac Disease Panel (tTG IgG, tTG IgA, DGP IgG)"

Tests: Array(3)

  0:

   Code: "GMA0304"

   Id: "e2bb4607-c227-4483-a3e9-55c1bc5a6781"

   Name: "Deamidated Gliadin Peptide (DGP) IgG"

 __proto__: Object

  1: {Id: "2fcd610f-d453-4c4f-a8dc-1a5f50e88548", Code: "GMA0301", Name: 

 "Tissue Transglutaminase (tTG) IgA"}

  2: {Id: "de41b236-4866-419a-a6f4-5f7c1440d30f", Code: "GMA0302", Name: 

 "Tissue Transglutaminase (tTG) IgG"}

 length: 3

 __proto__: Array(0)

 TestsSelectable: false

嘿,这是一个数组selectedPanels对象,它有另一个对象数组,我已经在面板中映射了这个对象,面板上有复选框,而Tests是一个可扩展的行数组,也有复选框


当我检查面板复选框时,它会检查测试的所有子复选框,并显示测试的长度说3,但是当我单击每个测试时,它应减去测试的长度,说3-1 = 2,它现在应该显示2,但是当我使用拼接,当我取消选择每个测试复选框时,它会删除整行,或者当我单击每个测试时,它已经实现时,它取消选择父面板复选框,当我取消选择每个测试时,我也不知道想要什么不删除文本,但减少数组的长度


您可以从该图像中看到

这是我的html文件


<label class="custom-control custom-checkbox">

    <input type="checkbox" class="custom-control-input" [name]="panel.Id + '-' + panel.Moniker" [ngModel]="checkAllTestsSelected(panel)"

      (ngModelChange)="onPanelCheckboxUpdate($event, panel)" [id]="panel.Id + '-' + panel.Moniker">

    <span class="custom-control-indicator"></span>

  </label>


 </ng-template>

 <ng-template ngbPanelContent>

<div class="individual-panel" *ngFor="let test of panel.Tests">

  <span class="text-dimmed">{{test.Name}}</span>

  <span *ngIf="panel.Name.includes('ENA') || panel.Name.includes('Celiac')">

  <label class="custom-control custom-checkbox">

    <input type="checkbox" class="custom-control-input" [name]="test.Id + '-' + test.Code"

           (ngModelChange)="onTestCheckboxUpdate($event, test, panel)" [id]="test.Id + '-' + test.Code">

    <span class="custom-control-indicator"></span>

  </label>

  </span>

</div>

数组在this.selectedPanels中如何解决此问题,有人可以帮忙吗?


收到一只叮咚
浏览 169回答 2
2回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答