如何在具有数字作为关键字的JSON数据上使用ng-repeat?

Var*_*kul 5 json angularjs

我想使用ng-repeat来显示像这样的JSON格式提供的数据表

{"name":"Aruba","code":"ABW","1960":54208,"1961":55435},
{"name":"Afghanistan","code":"AFG","1960":8774440,"1961":8953544}
Run Code Online (Sandbox Code Playgroud)

但是我的代码似乎不适用于{{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>
Run Code Online (Sandbox Code Playgroud)

当我删除<td>{{ country.1961 }}</td>一切正常.我该如何解决?

谢谢!

Nid*_*nan 4

{{country.1961}}对我来说效果很好,检查这个JSFiddle,但最好在以下情况下使用括号表示法而不是点表示法

  • 键是完整的数字,例如“1985”
  • 键包含“My Place”等空格

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>
Run Code Online (Sandbox Code Playgroud)