javascript - 根据表中不同的变体类型输入选择
问题描述
在我的项目中,我在一个表中发现了一个问题,我可以在其中选择intervention
. 有些干预措施是独特的,有些干预措施有变体。The problem arises when the selection of the variant (for example) c
, the intervention with the variant of type a
is 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
。怎么解决??
解决方案
推荐阅读
- python - Python 中包含哪些数据 int 对象?
- javascript - 如何并行遍历目录树?
- ruby - 在哈希迭代器中使用 proc 而不是块
- ubuntu - pip3 无法在 Windows 10 上的 Ubuntu 20.04 LTS 上创建虚拟环境,因为 ensurepip 不可用
- python - “‘numpy.ndarray’对象不可调用”在我的机器学习代码中
- python - 替换 set() 以保留重复项
- azure - Azure ARM 模板中的函数
- css - 网格动画的 Safari 问题
- mule - 动态查找后向 JSON 数组添加新项目
- azure - 来自 Log Analytics 聚合的饼图