我有一个REST服务,它返回类似于以下格式的JSON数据:
{
    "Africa" : [{
            "country" : "Nigeria",
            "capital" : "Abuja"
        }, {
            "country" : "Kenya",
            "capital" : "Nairobi"
        }, {
            "country" : "Ghana",
            "capital" : "Accra"
        }
    ],
    "Asia" : [{
            "country" : "India",
            "capital" : "New Delhi"
        }, {
            "country" : "China",
            "capital" : "Beijing"
        }
    ],
    "Europe" : [{
            "country" : "France",
            "capital" : "Paris"
        }
    ]
}我应该如何解析这个结果并填充一个与下面的图像类似的表:

http://jsfiddle.net/p7yLztwg/
发布于 2016-11-02 18:19:07
你可以试试这样的方法:
<table>
  <thead>
    <tr>
      <th>Continent</th>
      <th>Country</th>
      <th>Capital</th>
    </tr>
  </thead>
  <tbody ng-repeat="(continent, countries) in yourjsondata">
    <tr ng-repeat="country in countries">
      <td ng-if="$first" rowspan={{countries.length}}>{{ continent }}</td>
      <td>{{ country.country }}</td>
      <td>{{ country.capital }}</td>
    </tr>
  </tbody>
</table>这为每个大陆创造了一个tbody,为每个国家创造了一个tr。只有大陆的第一行才能得到该大陆名称的单元格。该单元格还会获得一个rowspan属性,以便它跨越多个行。
https://stackoverflow.com/questions/40386680
复制相似问题