Angular递归列表中,"list-group"不显示为子列表。
创始人
2024-10-24 12:33:06
0

在Angular递归列表中,如果您希望"list-group"不显示为子列表,可以通过条件判断来控制是否添加"list-group"类。

下面是一个示例代码,展示了如何使用条件判断来解决这个问题:


  • {{ item.name }}
    • No children
// app.component.ts
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  items = [
    {
      name: 'Parent 1',
      children: [
        {
          name: 'Child 1.1',
          children: [
            {
              name: 'Grandchild 1.1.1',
              children: []
            },
            {
              name: 'Grandchild 1.1.2',
              children: []
            }
          ]
        },
        {
          name: 'Child 1.2',
          children: []
        }
      ]
    },
    {
      name: 'Parent 2',
      children: []
    }
  ];
}

在上述示例中,使用了ngIf指令来判断是否添加子列表。如果"item"对象没有子项(children为空数组),则显示"No children"文本,否则递归调用自身(app-recursive-list)来显示子列表。这样可以避免在子列表中添加"list-group"类。

请注意,上述示例只是一种解决方法,实际应用中可能需要根据具体需求进行适当调整。

相关内容

热门资讯

透视技法!wepoker轻量版... 透视技法!wepoker轻量版透视方法(WePoKer祈福)总是真的是有辅助软件(哔哩哔哩)1、在w...
透视秘籍!wepoker免费脚... 透视秘籍!wepoker免费脚本咨询(德普之星有透视)真是有辅助教程(哔哩哔哩)1、许多玩家不知道w...
透视教材!werplan脚本(... 透视教材!werplan脚本(德普之星下载)切实是真的有辅助神器(哔哩哔哩)1、游戏颠覆性的策略玩法...
透视策略!xpoker辅助器(... 透视策略!xpoker辅助器(WePoKer透视脚本)一贯存在有辅助方法(哔哩哔哩)1、玩家可以在x...
透视方针!hhpoker德州作... 透视方针!hhpoker德州作必弊(WePoKer咨询)一贯真的有辅助教程(哔哩哔哩)透视方针!hh...
透视烘培!hhpoker透视脚... 透视烘培!hhpoker透视脚本视频(德普之星辅助软件)确实有辅助方法(哔哩哔哩)1、很好的工具软件...
透视积累!hhpoker德州透... 透视积累!hhpoker德州透视(德普之星开辅助)真是是真的有辅助技巧(哔哩哔哩)1、打开软件启动之...
透视法门!wepoker透视脚... 透视法门!wepoker透视脚本苹果版(AApoker安装包)确实有辅助技巧(哔哩哔哩)wepoke...
透视策略!聚星ai辅助工具下载... 透视策略!聚星ai辅助工具下载(WePoKer私人)都是是真的有辅助app(哔哩哔哩)聚星ai辅助工...
透视妙计!wepoker私人局... 透视妙计!wepoker私人局规律(德普之星有透视)原来是有辅助神器(哔哩哔哩)1、用户打开应用后不...