【问题标题】:Filter elements of an Observable<Array<Payload>>Observable<Array<Payload>> 的过滤器元素
【发布时间】:2022-01-28 11:08:12
【问题描述】:

我有这些帖子显示为卡片。

  posts: Observable<Array<TripPayload>>;

    export class TripPayload{
    id: String;
    content: String;
    title: String;
    price:Number;
    check_in_date:String;
    check_out_date:String;
    city:String;
    state:String;
    country:String;
}

我想通过 TripPayload 的属性(城市、国家、价格...)过滤它们,但我不知道如何访问它们。 我在后端做了一些过滤器,但如果我想在应用一个过滤器后应用第二个过滤器,我会得到 0 个帖子。我见过一些使用 MatTableDataSource 的好过滤器,但我认为我不能在这些情况下应用它们。

  filterPostsByLocation()


{
    this.posts = this.addPostService.filterPostsByLocation(this.country,this.state,this.city);
  }

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: angular typescript filter observable payload


【解决方案1】:

根据您的要求使用 Map 或 Pluck 运算符。下面是示例

filterPostsByLocation (): Observable<Recipe[]> {
    return this.http
        .get<Recipe[]>(this.locationURL)
        .pipe(map(res =>`${res.country}${res.state}${res.city}`));
}

https://chebbi-lamis.medium.com/rxjs-pluck-a-pound-of-pluck-is-worth-a-ton-of-map-f7cc600db371

【讨论】:

    猜你喜欢
    • 2020-05-30
    • 2019-01-21
    • 2017-12-30
    • 2017-12-13
    • 2015-08-15
    • 1970-01-01
    • 2015-08-27
    • 2010-10-03
    • 1970-01-01
    相关资源
    最近更新 更多