1
我的JSON數據是這樣的,幷包含在一個名爲「parks.json」文件:我想從一個角資源加載數據的一個子集
{
"description": "Farnborough features a good amount of green space and is indeed surrounded by plenty more. Our Parks section aims to tell you, not only where they all are but a little bit about the history behind them and the people who look after them today.",
"id": "parks",
"name": "Parks",
"locations": [
{
"name": "Queen Elizabeth Park",
"lat": 51.29692,
"lng": -0.76080000000000003,
"synopsis": "Once part of Windsor Great Park"
},
{
...
}
]
}
以下$資源的查詢將檢索上述數據的片段:
return $resource('locations/:categoryId.json', {}, {
query: {method:'GET', params:{categoryId:'categories'}, isArray:true}
});
的的categoryId在被傳遞是「公園」,因此上面的代碼將檢索我的整個Parks.jsonfile並將其加載到一個對象。這很好,但是,我想只將它的一部分提取到數組或對象中。
我的問題是我怎麼能適應上述提取的位置?我對lat和lng值特別感興趣。我已經有了其他各種各樣的工作,並且需要將這種行爲歸類,因爲我不太熟悉如何做到這一點。
乾杯!
Thanks @blesh - 最終我會將其轉移到一個寧靜的服務,但目前我正在經歷學習和原型的混合,因爲我學習以新的方式使用Javascript。所以你的回覆非常非常有用。我的項目將盡快使用普通的json文件。 –