[英]Ionic: change ion-list items on click
假设我有 3 个列表
清单:1)公共汽车,飞机
list: 2 ) [与巴士有关] 慢,不能飞
清单:3)【与飞机有关】速度快,能飞
在我的 Ionic Angular 项目中,我成功地制作了第一个离子列表。 但是如何通过单击其中的项目来更改整个离子列表?
[我明白了,它与(单击)function 有关,但我如何使用打字稿影响整个列表]
编辑:我得到你想要达到的目标。 您可以通过创建一个中间列表并在您的ngFor
中使用该列表来做到这一点。 这样,您只需将中间列表的引用更改为您喜欢的任何列表 onClick
export class ListPage {
transportationTypes: string[] = ['bus', 'plane'];
busSpecs: string[] = ['slow', "can't fly"];
planeSpecs: string[] = ['fast', 'can fly'];
currentList: string[] = this.transportationTypes;
itemClicked(type): void {
if (type === 'bus') {
this.currentList = this.busSpecs;
} else if(type === 'plane') {
this.currentList = this.planeSpecs;
} else {
this.currentList = this.transportationTypes;
}
}
}
在您的 HTML 中只需调用itemClicked
function
<ion-list *ngIf="currentList">
<ion-item *ngFor="let item of currentList" (click)="itemClicked(item)">
{{item}}
</ion-item>
</ion-list>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.