简体   繁体   中英

ng-repeat with arrays

{
"employees" : [ 
    {
        "name" : "XXX",
        "id" : "1",
        "Salary" : [ 
            {
                "Month" : "XXXX",
                "Amount" : "XXXX",
            }, 
            {
                "Month" : "XXXX",
                "Amount" : "XXXX",
            }, 
            {
                "Month" : "XXXX",
                "Amount" : "XXXX",
            }
        ]
    }, 
    {
        "name" : "YYY",
        "id" : "2",
        "Salary" : [ 
            {
                "Month" : "YYYY",
                "Amount" : "YYYY",
            }, 
            {
                "Month" : "YYYY",
                "Amount" : "YYYY",
            }, 
            {
                "Month" : "YYYY",
                "Amount" : "YYYY",
            }
        ]
    }
],
}

I have this type of object. I assigned this into vm.employess variable in controller. Now I want to repeat this in the HTML area. I managed to do this:

 <div ng-repeat="i in vm.employees">
            {{i.id}}
            {{i.name}}
   </div>

I want to repeat salary as well but I was unable to do that. Can anyone help me on that!

As you've nested json, you need to use nested ng-repeat

<div ng-repeat="i in vm.employees">
            {{i.id}}
            {{i.name}}
    <div ng-repeat="sal in i.Salary">
         {{sal.Month}}
         {{sal.Amount}}
    </div>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM