list - 在ionic 3中单击新项目时如何自动关闭手风琴列表中的项目
问题描述
这是我的 category.html 文件。我希望我的项目在单击打开新项目时自动关闭。
<ion-header>
<ion-navbar>
<ion-title>Category</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-list class="accordion-list">
<!-- First Level -->
<div *ngFor="let item of information;let i = index">
<ion-list-header no-lines no-padding>
<!-- Toggle Button -->
<button ion-item (click)="toggleSection(i,item.id)" detail-none
[ngClass]="{'section-active': item.open, 'section':!item.open}">
<ion-icon item-left name="add" *ngIf="!item.open"></ion-icon>
<ion-icon item-left name="close" *ngIf="item.open"></ion-icon>
{{ item.name }}
</button>
<ion-list *ngIf="item.open" no-lines>
<!-- Second Level -->
<div *ngFor="let child of childd; let j = index">
<ion-list-header *ngIf="child.count>1" no-padding>
<!-- Toggle Button -->
<button ion-item (click)="moveListPage(child.id,child.name)"
class="child" detail-none>
{{ child.name }}
</button>
</ion-list-header>
</div>
</ion-list>
</ion-list-header>
</div>
</ion-list>
</ion-content>
这是我的 category.ts 文件。我正在使用 woocommerce rest API 获取动态类别。希望一切正常,我遇到的问题是,当打开列表中的另一个项目时,前一个项目没有关闭。我已经搜索了很多,但得到了令人满意的结果。请帮我!!!!
let loading = this.loadingCtrl.create({
spinner:'dots'
});
loading.present();
setTimeout(() => {
loading.dismiss();
}, 6000);
this.WooCommerce = WC({
url: "http://wowvegetables.com",
consumerKey: "ck_a0b262448f5bacc9599ec992caafbd8812dab0e5",
consumerSecret: "cs_8af477cd84a65cfdac4ee42e0080fea4e4131807",
wpAPI: true,
version: "wc/v2"
});
this.WooCommerce.getAsync('products/categories?parent=0').then((result) => {
console.log(JSON.parse(result.toJSON().body));
this.information = JSON.parse(result.toJSON().body);
console.log(this.information);
return JSON.parse(result.toJSON().body);
}, (err) => {
console.log(err)
})}
cllapi(id){
this.id=id;
this.WooCommerce.getAsync("products/categories?per_page=70&parent="+
this.id).then((result) => {
console.log(JSON.parse(result.toJSON().body));
this.childd = JSON.parse(result.toJSON().body);
console.log(this.childd);
return JSON.parse(result.toJSON().body);
}, (err) => {
console.log(err)
})
}
ionViewDidLoad()
{
console.log('ionViewDidLoad CategoryPage'); }
toggleSection(i,id) {
this.cllapi(id);
this.information[i].open = !this.information[i].open;}
moveListPage(id,name) {
this.navCtrl.push(ListingtabPage, {
id: id,
name:name
});
}
}
解决方案
推荐阅读
- django - 在 django 应用程序中加载静态文件
- multithreading - Mybatis 扫描配置文件耗时较长
- .net - 使用 .resx 和 AngularJs 翻译
- java - 使用 InputSource 将 XML 解析为字符串会给出空文档
- ios - 在 UIcollectionViewCells 上快速绘制线条
- symfony - 如何使用 FOSUserBundle 引用 symfony 4.3 的邮件组件
- python - 在 3D 动画中保持恒定数量的可见球体在相机前面
- javascript - 如何在使用Javascript的字符串中出现另一个字符串标记之前插入一个字符串标记
- xml - Soap 请求所需信息 VB.net
- java - Java 中的 HttpPut 文件上传 - 覆盖 TrustStrategy:是否有“更好/更安全”的方式?