I am working with rxjs and angular 2 inside a service. I have json with which I was able to access with a get request .
private _campInfoUrl = 'api/campInfo/campInfo.json';
constructor(private _http: Http) { }
getAvailableCamps() {
return this._http.get(this._campInfoUrl)
.map((response: Response) => response.json())
At this moment I have all the data. However, to get into this object
{
"search": {
"startDate": "2016-06-07",
"endDate": "2016-06-10"
},
"reservations": [
{"campsiteId": 1, "startDate": "2016-06-01", "endDate": "2016-06-04"},
{"campsiteId": 1, "startDate": "2016-06-11", "endDate": "2016-06-13"},
{"campsiteId": 2, "startDate": "2016-06-08", "endDate": "2016-06-09"}
]
}
this is what i am trying to do
.map((response: Response) => response.json()) // <IProduct[]>
.map((tripDate) => ({
reservations: tripDate.reservations,
newRes: tripDate.search // <-- how to add this to every return object
}))
What I'm trying to figure out is a way with rxjs on how to get a “search” inside the backup array of such objects
"reservations": [
{
"campsiteId": 1,
"startDate": "2016-06-01",
"endDate": "2016-06-04",
"searchStartDate": "2016-06-07,
"searchEndDate": "2016-06-10
},
{
"campsiteId": 1,
"startDate": "2016-06-11",
"endDate": "2016-06-13",
"searchStartDate": "2016-06-07,
"searchEndDate": "2016-06-10
},
{
"campsiteId": 2,
"startDate": "2016-06-08",
"endDate": "2016-06-09",
"searchStartDate": "2016-06-07,
"searchEndDate": "2016-06-10
}
In the above example, I have a search object added to each index of the reservation array.
I was hoping this was a matter of concatenation or matching for array conversion. However, I cannot get inside each index into the reservation array.
Any understanding of navigating this json object would be greatly appreciated.