我想要API中的400个对象不是一次,而是10个组中的数组。控制台 - > [这里有10个对象],[另外10个],依此类推,直到400个对象完成,而不是在数组上,所有400个对象一次加载。
export class AppComponent {
data: any;
constructor(
private http: HttpClient) {}
ngOnInit() {
this.http.get('https://jsonplaceholder.typicode.com/comments')
.bufferCount(10, 10)
.subscribe(x => {
console.log(x)
}
}
我希望这样: (10)[{...},{...},{...},{...},{...},{...},{...},{... }] (10)[{...},{...},{...},{...},{...},{...},{...},{... }] ...
export class AppComponent {
constructor(
private http: HttpClient
) {
}
ngOnInit() {
this.http.get('https://jsonplaceholder.typicode.com/comments')
// missing piece - emits them one by one
.mergeAll()
.bufferCount(10,10)
.subscribe(x => {
console.log(x)
}
)
}
}
mergeAll逐个发出对象 然后,bufferCount可以将它们捆绑在10个组中