我繼續讀rxjs文檔,但在所有的運營商迷路..角2/RXJS - 需要一些幫助配料要求
這是我走到這一步,
let obs = Observable.from([1, 3, 5])
所以我需要這個要做的是take()
一些來自陣列的量。在發佈請求中使用結果,當成功發佈時,我需要重新啓動該過程。我想收集所有結果,並隨着流程的進展保持進度(對於進度條)
我不需要所有代碼。我真正需要知道的是如何使用rxjs來分割這個陣列..發送它的一部分,並重新啓動過程,直到沒有剩下發送。
最終解決
var _this = this
function productsRequest(arr) {
return _this.chainableRequest('post', `reports/${clientId}/${retailerId}/`, loadedProductsReport, {
'identifiers': arr,
'realTime': true
})
}
let arrayCount = Math.ceil(identifiers.length/10)
let obs = Observable.from(identifiers)
.bufferCount(10)
.concatMap(arr => {
arrayCount--
return arrayCount > 0 ? productsRequest(arr) : Observable.empty()
})
let subscriber = obs.subscribe(
value => console.log(value)
)
在父母
chainableRequest(method: string, endpoint: string, action: Function, data = {}, callback?: Function){
let body = (<any>Object).assign({}, {
headers: this.headers
}, data)
return this._http[method.toLowerCase()](`${this.baseUri}/${endpoint}`, body, body)
.map((res: Response) => res.json())
}
什麼即時試圖完成的就是把x數組中的項目 - >將它傳遞給http請求。 等待http請求完成,然後再次從頭開始傳遞項目。我已經嘗試了所有的例子,但沒有看到如何使我的工作做什麼即時通訊試圖做.. – hamobi
@hamobi當時可以用'concatMap()'來完成一個運行Observable。那麼你想從同一個數組重新啓動進程還是什麼? – martin
是的,我想重新從相同的數組進程。我想從數組中發送十個項目,然後接下來的十個項目,等等..直到我到達數組的末尾。謝謝:) – hamobi