AngularJS嵌套ng repeat的复杂JSON数据
我尝试将嵌套JSON数据访问到嵌套JSON数据中。我使用ng repeat,它适用于嵌套的JSON数据,但不适用于嵌套的JSON数据 我要捕获的数据是服务器URL及其名称AngularJS嵌套ng repeat的复杂JSON数据,json,angularjs,Json,Angularjs,我尝试将嵌套JSON数据访问到嵌套JSON数据中。我使用ng repeat,它适用于嵌套的JSON数据,但不适用于嵌套的JSON数据 我要捕获的数据是服务器URL及其名称 <tr ng-repeat="site in dT.data.sites"> <td>{{ site.siteName }}</td> <td><span ng-repeat="country in site.countries">{{ country.cou
<tr ng-repeat="site in dT.data.sites">
<td>{{ site.siteName }}</td>
<td><span ng-repeat="country in site.countries">{{ country.country + ' '}}<br><br></span></td>
<!-- Does not work -->
<td><span ng-repeat="country in site.countries">{{ country.masters.name }}</span></td>
<!-- Works, but displays only the first element of the array because of the [0] -->
<td><span ng-repeat="country in site.countries">{{ country.masters[0].name }}</span></td>
<!-- Does not work -->
<td><span ng-repeat="master in site.countries.masters">{{ master.name }}</span></td>
<td></td>
<td></td>
</tr>
{{site.siteName}
{{country.country+''}}
{{country.masters.name}
{{country.masters[0].name}
{{master.name}}
也许我必须使用一个带有if…else方法的函数。
或者使用服务,但我更喜欢使用ng repeat。您必须在另一个
ng repeat
中执行ng repeat
。大概是这样的:
<td><span ng-repeat="country in site.countries"><span ng-repeat="master in country.masters">{{ master.name }}<br /></span></span></td>
{{master.name}}
我已对您的plunker进行了更改,以显示其工作:
这就是你要找的吗
<td><span ng-repeat="country in site.countries[0].masters">{{ country.server + ':' + country.name + ', ' }}</span></td>
{{country.server+':'+country.name+','}
看