【问题标题】:How to make a filter with an observable如何使用 observable 制作过滤器
【发布时间】:2021-06-03 05:33:13
【问题描述】:

我正在尝试对我的 observable 进行过滤

private ListpplSource = new BehaviorSubject<ppl[]>([]);

  Listppl$ = this.ListpplSource.asObservable();

  ShowAllPpl(){
    this.service.bringAllppl().subscribe(data =>{
      this.ListpplSource!.pipe (
        map(items => 
         items.filter(item => item.codempresa == 1 ))).next(data)
    
         
    })
  }

但我在.next(data) 上显示红色下划线:

“Observable”类型上不存在属性“next”。

所以基本上我希望我的 Listppl$ 只获取 item.codempresa == 1 的项目,因为我的服务给我带来了所有的对象,而我只是一个有 item.codempresa == 1 的对象。我需要使用下一个(数据)使其始终可见

【问题讨论】:

  • 您是否要过滤通过bringAllppl()方法获取的数据,然后将过滤后的数据发送到Listppl$ Observable?我说的对吗?

标签: angular rxjs


【解决方案1】:

我想你想要这样的东西:

this.service.bringAllppl().subscribe(data => {
  const filteredData = data.filter(item => item.codempresa === 1);
  this.ListppSource.next(filteredData);
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-22
    • 2020-05-18
    • 1970-01-01
    • 2023-04-07
    • 2021-03-19
    • 2019-09-06
    • 1970-01-01
    • 2018-05-25
    相关资源
    最近更新 更多