首页 > 解决方案 > 根据表中不同的变体类型输入选择

问题描述

在我的项目中,我在一个表中发现了一个问题,我可以在其中选择intervention. 有些干预措施是独特的,有些干预措施有变体。The problem arises when the selection of the variant (for example) c, the intervention with the variant of type ais always obtained. 从一开始我就有class这种类型:

-------------
Intervention
-------------
id: number
code: string
description: string

-----------------------
InterventionAssociation
-----------------------
id: number
intervention: Intervention
price: number
variant: string

variants?: string[] //used for contain all variants


干预中现有数据的一个例子是:

[1 , "A", "good"] 
[2 , "B", "ok"]
[3 , "C", "no"]

AssociationIntervention 中的当前数据示例如下:

[1 , 1 , 22.16 , null] 
[2 , 2 , 18.17 , "a"]
[3 , 2 , 32.15 , "b"]
[4 , 3 , 10.29 , null]
 

我页面上的表格如下所示:

<table class="table">
      <thead>
        <tr>
          <th scope="colgroup">Code</th>
          <th scope="colgroup">Price</th>
          <th scope="colgroup">Select</th>
        </tr>
      </thead>
      <tbody>
        <ng-container *ngFor="let type of interventionVar; index as i">
          <tr *ngFor="let variant of type.variants; index as j">
            <td>{{type.intervention.code}} - {{type.variants[j]}}</td>
            <td>{{type.price[j]}}</td>
            
            <td>
              <div class="custom-control custom-checkbox">
                <input type="checkbox" class="form-check-input" (click)="press(type, j)">
              </div>
            </td>
          </tr>
        </ng-container>
      </tbody>
    </table>

里面的方法ts是这样的:

interventionVar: AssociationIntervention[]
selectedElement: AssociationIntervention

press(selected: AssociationIntervention[], variant: number) {
    const newInterv = Object.assign({}, selected)
    this.selectedElement.push(newInterv)
    console.log(this.selectedElement)
}

问题是,即使使用上述数据我选择了干预B - b,或者在其他情况下“始终 - 不是”,我也会始终选择干预B - a。怎么解决??

标签: javascripthtmlarraysangulartypescript

解决方案


推荐阅读