删除元素后如何刷新ionic 4列表项
how to refresh ionic 4 list items after deleting an element
我想做的是在删除元素后刷新 ionic 4 列表项,因为我收到以下错误:
html:
<ion-list [hidden]="showAllStations==false">
<ion-item *ngFor="let item of wayPoints; let i = index">
<ion-label>{{item.location}}</ion-label>
<ion-checkbox slot="start"
(ionChange)="delete(i)"></ion-checkbox>
</ion-item>
<ion-button type="submit" (click)="deletStations()" expand="block" class="ion-text-center ion-margin-top" >Valide</ion-button>
</ion-list>
ts:
delete(index){
console.log(index);
this.deletedStations.push(index);
// delete this.wayPoints[index];
console.log(this.deletedStations);
}
deletStations(){
this.deletedStations.forEach(index => delete this.wayPoints[index]);
console.log(this.wayPoints);
this.modalCtrl.dismiss(this.wayPoints);
}
错误:
ERROR TypeError: Cannot read property 'location' of undefined
试试这个:
delete(index){
this.wayPoints.splice(index, 1);
}
您应该使用上述方法简单地从数组中删除项目,您的数组将自动更新并且更改将反映在列表的前端,在这种情况下您不需要手动刷新列表.
祝你好运 :)
{this.responselist.splice(this.index,1); }
我想做的是在删除元素后刷新 ionic 4 列表项,因为我收到以下错误:
html:
<ion-list [hidden]="showAllStations==false">
<ion-item *ngFor="let item of wayPoints; let i = index">
<ion-label>{{item.location}}</ion-label>
<ion-checkbox slot="start"
(ionChange)="delete(i)"></ion-checkbox>
</ion-item>
<ion-button type="submit" (click)="deletStations()" expand="block" class="ion-text-center ion-margin-top" >Valide</ion-button>
</ion-list>
ts:
delete(index){
console.log(index);
this.deletedStations.push(index);
// delete this.wayPoints[index];
console.log(this.deletedStations);
}
deletStations(){
this.deletedStations.forEach(index => delete this.wayPoints[index]);
console.log(this.wayPoints);
this.modalCtrl.dismiss(this.wayPoints);
}
错误:
ERROR TypeError: Cannot read property 'location' of undefined
试试这个:
delete(index){
this.wayPoints.splice(index, 1);
}
您应该使用上述方法简单地从数组中删除项目,您的数组将自动更新并且更改将反映在列表的前端,在这种情况下您不需要手动刷新列表. 祝你好运 :)
{this.responselist.splice(this.index,1); }