【发布时间】:2020-06-20 02:30:20
【问题描述】:
我有一个带有数组的数组,它模拟了一本 csv 书:
[
[ 'PROBANDO', 'SUBIENDO DESDE CSV', '1', '900', '', '2', '1' ],
[ 'PROBANDO', 'SUBIENDO DESDE CSV', '1', '900', '850', '3', '1' ],
[ 'PROBANDO', 'SUBIENDO DESDE CSV', '1', '900', '850', '2', '1' ]
]
我想要的是选择一个类别(索引 6)并在数组中更改它。
此代码完美地更改了类别,但我必须再次选择我选择的类别才能保持选中状态。
ts
selectCat(event, idx: any) {
let prod: any[] = this.productos[idx];
prod.splice(6, 1, event.target.value); // 6 = posicion de la columna categoria
this.productos.splice(idx, 1, prod);
}
html
<tr *ngFor="let p of productos; index as idx">
<td *ngFor="let i of p; index as ind">
<p *ngIf="ind <= 4"> {{ i }} </p>
<select *ngIf="ind == 6" name="cat" (change)="selectCat($event, idx)"
class="form-control form-control-sm">
<option *ngFor="let c of categorias" [value]="c.id"> {{ c.categoria }}
</option>
</select>
</td>
</tr>
类别数组:
[
{id: 2, categoria: "Cat22"},
{id: 3, categoria: "cat3"},
{id: 1, categoria: "Ropa"}
]
------------------------------------------ ---------------
我做错了什么?
【问题讨论】:
-
你能提供你的分类数组吗?
-
@SurajGupta 添加
-
我已经创建了相同的演示,请看看link
-
@SurajGupta 是的,问题是 ngModel 丢失了!非常感谢
标签: html angular typescript