gpt4 book ai didi

Angular 5 展开/折叠列表

转载 作者:搜寻专家 更新时间:2023-10-30 21:16:28 24 4
gpt4 key购买 nike

我使用 Material 列表控件来显示嵌套对象。我用 div 创建了垫子列表,但我想在这里添加展开/折叠行选项,当我点击行时它应该显示子类别 div ?

 <mat-list>
<div *ngFor="let item of chaptersItems">
<mat-list-item>
<a style="cursor: pointer;">
<h4 mat-line>{{item.name}} {{item.description}}</h4>
</a>
</mat-list-item>
<mat-list style="margin-left:30px;">
<div *ngFor="let subItem of item.subChapters">
<mat-list-item>
<a style="cursor: pointer;">
<p mat-line> {{subItem.name}}. {{subItem.description}}</p>
</a>
</mat-list-item>
</div>
</mat-list>
</div>
</mat-list>

如何在 div 或 mat-list 控件上实现点击功能?

最佳答案

您可以按照此处所述将每个项目包装到 mat-expansion-panel 包装器中: https://material.angular.io/components/expansion/overview

看起来像这样:

<mat-list>
<div *ngFor="let item of chaptersItems">
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-list-item>
<a style="cursor: pointer;">
<h4 mat-line>{{item.name}} {{item.description}}</h4>
</a>
</mat-list-item>
<mat-expansion-panel-header>
<mat-list style="margin-left:30px;">
<div *ngFor="let subItem of item.subChapters">
<mat-list-item>
<a style="cursor: pointer;">
<p mat-line> {{subItem.name}}. {{subItem.description}}</p>
</a>
</mat-list-item>
</div>
</mat-list>
</mat-expansion-panel>
</div>
</mat-list>

关于Angular 5 展开/折叠列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48687758/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com