我正在使用从Json请求收到的数据创建无限滚动表。 问题是我需要在promise的第一个响应之后添加scroll observable。
//Set Observables
var column = this.refs.column;
var columnScrollStream = Rx.Observable.fromEvent(column, 'scroll').filter(function () {
return (column.scrollHeight - column.scrollTop == columnHeight);
});
var refreshTimeStream = Rx.Observable.timer(0, 30000);
var columnScrollSubscription = columnScrollStream.subscribe(function (scroll) {
paginationNo += 10;
});
//Merge Observables
var requestStream = Rx.Observable
.merge(refreshTimeStream, columnScrollStream)
.map(function() {
return url+'/0/'+paginationNo;
};
// Use Observables
var responseStream = requestStream
.throttle(400).flatMapLatest(function(requestUrl) {
return Rx.Observable.fromPromise(jQuery.getJSON(requestUrl));
});
//Use result
this.subscription = responseStream.subscribe(function(result) {
/* use result here*/
/* !!! Place where the scoll Observable should be, because the column ref gets created only after the result is delivered */