search

Home  >  Q&A  >  body text

javascript - angular ng-repeat的问题

我本地写了个json文件叫demo.js,然后我想ng-repeat里面的数据。现在遇到的问题是:
我不知道怎么循环出roles的数据。

{
    "demoData": [
        {
            "dp": "aaa1",
            "name": "用户名1",
            "number": "11111",
            "score": "22222",
            "salary": "11111",
            "jobs": "scripts",
            "roles": [
                {
                    "new": "bbb",
                    "edit": "ddd",
                    "ccc": "aaaa",
                    "del": "dddd"
                }
            ],
            "other": "备注",
            "action": "删除"
        },
        {
            "dp": "bbb",
            "name": "用户名1",
            "number": "11111",
            "score": "22222",
            "salary": "11111",
            "jobs": "scripts",
            "roles": [
                {
                    "new": "bbb",
                    "edit": "ddd",
                    "ccc": "aaaa",
                    "del": "dddd"
                }
            ],
            "other": "备注",
            "action": "删除"
        }
    ]
}
PHP中文网PHP中文网2743 days ago700

reply all(5)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-15 17:16:10

        <h1 ng-repeat="item in demoData[0].roles">{{item}}</h1>

    reply
    0
  • 迷茫

    迷茫2017-05-15 17:16:10

        //如果是要在html里面用的话楼上的方法可以
        //<h1 ng-repeat="item in demoData[0].roles">{{item}}</h1>
        angular.forEach(demoData,function(data,index,array){
            angular.forEach(data.roles,function(role,index,array){
                console.log(role);
            })
        })

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-15 17:16:10

     <p ng-repeat="(item,index) in demoData">
        <p ng-repeat="item in demoData[index].roles">
            {{item}}
        </p>
    </p>

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-15 17:16:10

    It can be solved by two levels of nesting

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-15 17:16:10

    Nested Loops

    <p ng-repeat="item in demoData">
        <p ng-repeat="item2 in item.roles">
            {{item2}}
        </p>
    </p>

    reply
    0
  • Cancelreply