0
JSON數據,角2(打字稿) - RxJS可觀察到的 - GROUPBY
{
"name": "Sam",
"age":25,
"schools":
[
{
"country":"USA",
"state":"IN",
"city":"Fishers",
"name":"school 1"
},
{
"country":"USA",
"state":"IN",
"city":"Indianapolis",
"name":"school 2"
},
{
"country":"USA",
"state":"CO",
"city":"Denver",
"name":"school 3"
},
{
"country":"Canada",
"state":"Ontario",
"city":"Toronto",
"name":"school 4"
}
]
}
我需要組通過對學校陣列上的「國家」,然後按「狀態」,然後「城市」。
我的打字稿接口,
interface Person{
name:string;
age:number;
schools: School[];
}
interface School{
country:string;
states: State[];
}
interface State{
state:string;
pairs: Pair[];
}
interface Pair{
city:string;
name:string;
}
我需要寫一個服務方法,讓學校按國家和國家分組由國家分組,各城市和名稱分組到JSON數據轉換到我的模型。
是我的模型結構是否正確?如果是這樣,我怎麼根據我的需要做分組。
我的服務方法看起來應該像這樣的事情,
getPerson():Observable<Person>
{
return this.http.get(url to get json data).groupBy(XYZ..).....
}
的可能的複製[如何GROUPBY上一個HTTP響應?](https://stackoverflow.com/questions/43096470/how-do-i-groupby-on-a-http-response) – mxr7350