使用ng-repeat嵌套ui li

时间:2016-06-27 12:44:59

标签: javascript jquery angularjs

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"},
    ]
  },
 ]

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

1 个答案:

答案 0 :(得分:0)

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