简体   繁体   中英

AngularJS ng-repeat through json array doesnt work in second array

I'm trying to do a ng-repeat over a json array. I'm able to do the first iteration of 'event in calendar'. But I'd not have to manually iterate through each number. This works:

<div ng-repeat="event in calendar">
          {{event[0].custom_fields.location[0]}}
          {{event[0].custom_fields.price[0]}}
          {{event[1].custom_fields.location[0]}}
          {{event[1].custom_fields.price[0]}}  
          {{event[2].custom_fields.location[0]}}
          {{event[2].custom_fields.price[0]}}        
</div>

I've tired doing two ng-repeats and it fails. How do I fix this?

<div ng-repeat="event in calendar">
          <div ng-repeat="custom_fields in event.custom_fields">
             {{custom_fields.location[0]}}
             {{custom_fields.price[0]}}
          </div>
</div>

According to your first example, event is the array, not the custom_fields property. Iterate it instead.

<div ng-repeat="events in calendar">
    <div ng-repeat="event in events">
        {{event.custom_fields.location[0]}}
        {{event.custom_fields.price[0]}}
     </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