我想使用ng-repeat来显示数据表 提供像这样的JSON格式
{"name":"Aruba","code":"ABW","1960":54208,"1961":55435},
{"name":"Afghanistan","code":"AFG","1960":8774440,"1961":8953544}
但我的代码似乎不适用于{{country.1961}}。
<table>
<tr>
<td>Country name</td>
<td>1960 population</td>
<td>1970 population</td>
<td>1980 population</td>
<td>1990 population</td>
<td>2000 population</td>
<td>2010 population</td>
<td>Percentage growth between 1960 and 2010</td>
</tr>
<tr ng-repeat="country in countries">
<td>{{ country.name }}</td>
<td>{{ country.1961 }}</td>
</tr>
</table>
当我删除<td>{{ country.1961 }}</td>
时,一切正常。
我该如何解决?
谢谢!
答案 0 :(得分:4)
{{country.1961}}
对我来说很好用,请查看 JSFiddle ,
但是,当
<强> JSFiddle 强>
<table border='1'>
<tr>
<td>Country name</td>
<td>1960 population</td>
<td>1970 population</td>
<td>1980 population</td>
<td>1990 population</td>
<td>2000 population</td>
<td>2010 population</td>
<td>Percentage growth between 1960 and 2010</td>
</tr>
<tr ng-repeat="country in countries">
<td>{{ country.name }}</td>
<td>{{ country['1961'] }}</td>
</tr>
</table>
答案 1 :(得分:2)
您可以使用backet表示法{{country['1961']}}
。