我有一个带有子项目的菜单,并且除初始加载外,其他所有东西都工作正常,如果该父项的任何子级具有“活动”类,则我希望默认打开子项的父项。
如果满足条件,我就给子元素“活动”类,如果该父项中的任何孩子都满足条件,我也想给它的父类“活动”。
<ion-menu side="end" menuId="sideMenu" id="sideMenu" contentId="mainMenu" swipe-gesture="false">
<ion-header>
<ion-toolbar color="primary">
<ion-title>Steps</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<div *ngFor="let p of menu">
<ion-item button *ngIf="p.children?.length > 0" (click)="p.open = !p.open" [class.active-parent]="p.open" detail="false">
<ion-icon slot="start" name="arrow-forward" *ngIf="!p.open">,/</ion-icon>
<ion-icon slot="start" name="arrow-down" *ngIf="p.open">,/</ion-icon>
<ion-label>{{ p.title }}</ion-label>
</ion-item>
<ion-list *ngIf="p.open">
<ion-menu-toggle>
<ion-item class="sub-item" *ngFor="let sub of p.children" [routerLink]="['/main', gameId, sub.steps_id]" routerDirection="root" [ngClass]="{'active': sub.steps_id==stepId}">
<ion-label>
{{ sub.name }}
</ion-label>
</ion-item>
</ion-menu-toggle>
</ion-list>
</div>
</ion-content>
</ion-menu>
我有一个带有子项目的菜单,并且除初始加载外,其他所有东西都工作正常,如果该父项的任何子级具有“活动”类,则我希望默认打开子项的父项。我给...
使用Array.prototype.some(),您可以检查p.children
中的任何项目是否满足条件sub.steps_id==stepId