对象列表上的bufferCount - 10个包不起作用

问题描述 投票:0回答:1

我想要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)
      }
}  

代码为我提供了一个包含API中500个对象的数组。像这样:enter image description here

我希望这样: (10)[{...},{...},{...},{...},{...},{...},{...},{... }] (10)[{...},{...},{...},{...},{...},{...},{...},{... }] ...

javascript angular observable
1个回答
0
投票
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个组中

© www.soinside.com 2019 - 2024. All rights reserved.