这是我的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
});
}
}