嵌套ui li使用ng-repeat [重复]

时间:2022-08-23 23:40:37

This question already has an answer here:

这个问题在这里已有答案:

var data = [
  {
    "id": 0,
    "name": "Will choose later"
  },
  {
    "id": 999999,
    "name": "I have my own option"
  },
  {
    "id": 1,
    "name": "Option 1",
    "list": [
        {"id": 1, "name": "Sub 1", 
        "list": [
            {"id": 1, "name": "Sub 1"},
            {"id": 2, "name": "Sub 2"},
        ]},
    ]
  },
  {
    "id": 2,
    "name": "Option 2",
    "list": [
      {"id": 1, "name": "Option 2 - Sub 1"},
      {"id": 2, "name": "Option 2 - Sub 2"},
      {"id": 3, "name": "Option 2 - Sub 3"},
    ]
  },
 ]

Here array structure is dynamic, list object may repeat more. Is it possible to create a nested ul li only using by ng-repat (only playing in html). I have tried but as list object is dynamic I couldn't make it work. I am trying in angular but will ok in jquery as well.Please suggest.

这里的数组结构是动态的,列表对象可能会重复更多。是否可以仅使用ng-repat创建嵌套的ul li(仅在html中播放)。我尝试过,但由于列表对象是动态的,我无法使其工作。我正在尝试角度,但也可以在jquery中使用。请建议。

1 个解决方案

#1


0  

<div ng-repeat="d in data">
{{d.id}}
   <div ng-repeat="l in d.list">
       {{l.name}}
   </div>
</div>

#1


0  

<div ng-repeat="d in data">
{{d.id}}
   <div ng-repeat="l in d.list">
       {{l.name}}
   </div>
</div>