Angular ng-repeat嵌套数组

时间:2015-11-03 04:26:45

标签: angularjs

我有这个数组

 {
    "menus": [
        {
            "id": "4",
            "name": "Administrator",
            "icon": "symbol-male",
            "is_show": "1",
            "sub_menus": [
                {
                    "id": "6",
                    "admin_menu_id": "4",
                    "name": "Manage Admin Role",
                    "link": "admin-roles",
                    "is_show": "1"
                },
                {
                    "id": "5",
                    "admin_menu_id": "4",
                    "name": "Manage Administrator",
                    "link": "admins",
                    "is_show": "1"
                }
            ]
        }
    ]
}

如何使用菜单正确重复sub_menus?

我试过

 <ul>
    <li ng-repeat="menu in menus">{{ menu.name }}
        <ul>
            <li ng-repeat="sub_menu in menu.sub_menus">{{ sub_menu.name}} </li>
        </ul>
    </li>
 </ul>

但是当我重复它时,sub_menus.name没有显示。

1 个答案:

答案 0 :(得分:2)

你的html需要如下所示。

  <ul>
    <li ng-repeat="menu in menuItems.menus">{{ menu.name }}
        <ul>
            <li ng-repeat="sub_menu in menu.sub_menus">{{ sub_menu.name}} </li>
        </ul>
    </li>
 </ul>

已对此JSFiddle

采取行动