1
我遇到的问题是不显示显示和隐藏功能。问题是能够为所选按钮获取正确的索引。下面我抓住第二个数组的索引。如果用户要选择每个currentItems数组的第一个项目,则所有的第一个项目都会打开和关闭。我想要的只是被选择关闭和打开的那个。点击resultInfo数组,我想要显示itemInfo。隐藏并显示项目点击存储在多个阵列 - ionic 2+/angular 2+
HTML
<div *ngFor="let a of currentItems">
<ion-item-sliding id="rightdiv" *ngFor="let b of a.resultInfo; index as i">
<button ion-item (click)="toggleGroup(i)" [ngClass]="{active: isGroupShown(i)}" class="destInfo">
<h3>click me</h3>
</button>
<ion-item [class.hidden]="!isGroupShown(i)" *ngFor="let c of b.itemInfo">
<ion-label>{{c.name}}</ion-label>
</ion-item>
</ion-item-sliding>
</div>
TS
shownGroup = null;
toggleGroup(group) {
if (this.isGroupShown(group)) {
this.shownGroup = null;
} else {
this.shownGroup = group;
console.log(this.shownGroup, 'SHOWN GROUP HERE')
}
}
isGroupShown(group) {
return this.shownGroup === group;
};
DATA
currentItems = [
{
"time": "a some time",
"resultInfo": [
{
"about": "some place",
"itemInfo": [
{
"name": "someName"
},
]
}
]
},
{
"time": "some time",
"resultInfo": [
{
"about": "some place",
"itemInfo": [
{
"name": "someName"
},
]
}
]
}
]
在您的功能 this.c = currentItems [index] .resultInfo [0] .itemInfo [0] – Swoox