不幸的是,這樣的網站是設置,我需要檢索的數據,是該數據在多個站點傳播(類型完全相同的數據和JSON返回格式),但它們位於不同的URL。他們被URL分類,所以我確實需要保留這些URL,以便在整個應用程序中對其進行進一步分類。我有以下服務功能,我正在嘗試傳遞一組主題(然後傳遞給URL),檢索數據並返回單個可觀察項。然而,這回什麼:角服務功能不返回任何東西,嘗試做多個HTTP請求,並返回單一可觀察
getDataTopicItems(topicArray) {
return this.items = topicArray.forEach((topic, i, topicArray) => {
return this.http.get(this.baseUrl + topic + "/_api/Web/Lists/GetByTitle('What''s New')/items", this.options)
.map(res => res.json())
.map(items => items.d.results)
.do(data => console.log(data))
.concatMap(data => data)
}
)
}
我訂閱了它在我通過* ngFor加上一個異步管道調用這個函數組件的模板。我究竟做錯了什麼?
更新:我也試過如下:
return this.http.get(this.baseUrl + topicArray[0] + this.policyOptions, this.options)
.map(res => res.json())
.map(items => this.policies = items.d.results)
.do(data => console.log(data))
.flatMap((policies) => topicArray.forEach((topic, i, topicArray) => {
if (i < 0) {
this.http.get(this.baseUrl + topic + this.policyOptions)
.map(res => res.json())
.map(items => this.policies = items.d.results)
.do(data => console.log(data))
}
}))
更改的forEach映射也不起作用。在這兩種情況下,它都沒有console.log數據。 – kittycatbytes