我是 rxjs 的新手,我正在尝试传递参数,Subject.next(args)
我有以下类:
@Injectable()
export class ListPosts {
baseURL: string = 'http://localhost/wptest/api';
_load = new Subject();
constructor(private http: Http) {
var currentPage = this._load
.scan((currentPage) => currentPage + 1, 0)
var postResponses = currentPage //args here is undefined
.flatMap(args => this.fetchPosts(args))
.share();
var loadedPosts = postResponses
.map(json => json.posts)
.scan((allPosts, newPosts) => allPosts.concat(newPosts), []);
this.loadedPostCount = loadedPosts.map(p => p.length);
this.totalPostCount = postResponses.map(json => json.count_total);
this.completed = Observable.combineLatest(this.loadedPostCount, this.totalPostCount, (loaded, total) => loaded >= total);
this.posts = loadedPosts;
}
fetchPosts(args: any) {
console.log("count: " + args[0] + " page :" + args[1] + " type: "+ args[2]);
}
loadMore(args: any) {
this._load.next(args);
}
}
但如果我currentPage
改为this._load
,它的工作原理
var postResponses = this._load
.flatMap(args => this.fetchPosts(args)) //args here is defined
.share();
我需要通过 args currentPage
,我该如何解决?