【发布时间】:2017-02-03 07:36:48
【问题描述】:
我有一个从服务器返回的数组,并通过在表中使用 *ngFor 来显示项目。处理完所选项目后,我会将其从数组中删除。该视图不会自动删除已删除的项目。但是,如果单击表头中的排序功能,则删除的项目将从视图中删除。我知道即使数组已在内部更新,我也需要通知视图数组已更改。但我找不到让它工作的方法。我希望有人能给我一个提示。谢谢。
Patient.ts
public _records: Array<CRCasesLite>;
constructor(private router: Router,
private route: ActivatedRoute) {
this._records = this.route.snapshot.data['crCasesLite'];
}
onActivateRecord(record: CRCasesLite, index: number): void {
...
if (index > -1) {
this._records.splice(index, 1);;
}
}
Patients.html
<th class="input-sm">Patient <a (click)="oby=['PatientName']" class="fa fa-caret-up fa-2x"></a> <a (click)="oby=['-PatientName']" class="fa fa-caret-down fa-2x"></a></th>
<tr *ngFor="let record of _records | orderBy : oby ? oby : ['']; let i = index; trackBy:index">
<td class="input-sm">{{record.PatientName}} {{record.Id}}</td>
<td><a class="link btn btn-primary fa fa-plus-square" (click)="onActivateRecord(record, i)"></a></td>
【问题讨论】: