ionic-framework - 如何根据传递的 id 激活离子切换?
问题描述
我有很多帖子,我必须只激活用户点击的视图切换。但是当点击一个帖子的按钮时,每个帖子的按钮都是活动的,尽管它没有更新到数据库中。
<p class="font">
<strong>Space Type: </strong>{{ post.AvailableSpace.Space.SpaceTypeName }}
<br> <strong>Address: </strong> {{ post.AvailableSpace.Address}}
<br><strong>Price: </strong> {{ post.AvailableSpace.Price }} {{ post.AvailableSpace.PriceType.PriceTypeName}}
<br><strong>No of available rooms: </strong> {{post.AvailableSpace.NoOfRooms}}
<br>
</p>
解决方案
您应该使用 *ngFor 和 ngClass 来轻松切换某些东西。
.ts 文件
examples: any = [];
toggleSection(i) {
this.examples[i].open = !this.examples[i].open;
}
.html 文件
<ion-list *ngFor="let item of examples; let i = index">
<ion-item (click)="toggleSection(i)" [ngClass]="{'section-active': item.open}">
</ion-item>
<ion-card *ngIf="item.open"> Hello </ion-card>
</ion-list>
推荐阅读
- postgresql - 导出到文件时格式化数据?
- c - 当“aa”字符串分配给整数变量时发生了什么?
- unity3d - 无法加载文件或程序集“Facebook.Unity.Canvas”
- java - 以编程方式单击工具栏中的后退箭头
- ghostscript - GhostScript和Xpdf在将pdf转换为png上有什么区别
- javascript - 谷歌登录api(platform.js)设置没有SameSite属性的cookie?
- android - 无线运行/安装/调试 android 应用程序,但通过其自己的便携式热点
- .net-core - WSO2 API 管理器与微型网关
- jquery - 使用 JQuery 对选择选项进行排序
- r - 为什么当我使用 rep() 时 rbind 不起作用?