1
我需要使用兩個具有Angular ng-repeat的API生成如下所示的表格?如何做到這一點如何使用JSON映射響應生成Angular ng表格
+---------------+---------------------+------------+------------+
| Continent | Continent Shortcode | City | Population |
+---------------+---------------------+------------+------------+
| Asia | AS | Beijing | 21.5 |
| | | Manila | 1.6 |
| Europe | EU | London | 8.6 |
| | | Paris | 2.2 |
| North America | NA | Washington | 7 |
| South America | SA | Brasilia | 2.5 |
| Australia | AU | Canberra | 0.3 |
+---------------+---------------------+------------+------------+
REST端點getCityStatsByContinent(continentId)
? - > /API /統計/城市/列表大陸= 100,200,300,400,500
{
"100" : [{
"city" : "Beijing",
"population" : 21.5m
}, {
"city" : "Manila",
"population" : 1.6m
}
],
"200" : [{
"city" : "London",
"population" : 8.6m
}, {
"city" : "Paris",
"population" : 2.2m
}
],
"300" : [{
"city" : "Washington",
"population" : 7m
}
],
"400" : [{
"city" : "Brasilia",
"population" : 2.5m
}
],
"500" : [{
"city" : "Canberra",
"population" : 0.3m
}
],
}
爲getContinetDetails()
REST端點 - >/API /大洲
[
{
"id" : 100,
"code" : "AS",
"name" : "Asia"
}, {
"id" : 200,
"code" : "EU",
"name" : "Europe"
}, {
"id" : 300,
"code" : "NA",
"name" : "North America"
}, {
"id" : 400
"code" : "SA",
"name" : "South America"
}, {
"id" : 500,
"code" : "AU",
"name" : "Australia"
}
]
我只能想到從下面的代碼開始(假設第一個API響應存儲在citiesByContinentId中)。但我堅持的東西應該是解決從/ API的continentId正確的方法/大洲
<tr ng-repeat ="(continentId, cityStats) in citiesByContinentId">
<td>{{ continentId }}</td>
<tr>
假設$ scope.continentDetails返回100K記錄,將在不影響性能在100K記錄上重複執行。這是唯一的解決方案嗎?還是應該解決這個問題? – FakirTrappedInCode
在這種情況下,您需要爲記錄實現**分頁**和**單個綁定('{{:: city.city}}')**。 –