nickdnk nickdnk - 1 year ago 126
AngularJS Question

Nested ng-repeat with attribute from parent ng-repeat

I have a JSON object (

) which contains an array called
. This array contains titles (
) and IDs (
) of "rooms" that are also a part of the JSON object. This means you can do
and get the array that contains the objects of each room. I have a hard time making this work in Angular.

It was built this way because it makes it easy to work with when it comes to UITableViews in iOS (where it's implemented and works). Therefore I cannot change the data. I tried below solution, but that gives me an error. Is there an effective way to do this in Angular?

<tbody data-ng-repeat="section in tbls.sections">

<tr data-ng-repeat="table in tbls.{{section.viewid}}">

JSON JSFiddle:
Edit: removed tableObj as it's not relevant to the question and doesn't match data example exactly. Same logical problem though.

Edit: Since I asked this question I have changed it to be properly nested with an array of sections containing what is in that section as well. Don't do what I did in this question, originally.

Answer Source

You just need to use standard [] javascript object syntax:

<tr data-ng-repeat="table in tbls[section.viewid]">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download