2021年1月28日星期四

filter result of observable

I have a service which returns an observable of organization object, and I want to filter the result based on organizationID I pass.

Currently I am doing something like this, but it returns me all the values instead of filtered one.

filteredOrganization(organizationId: number) {    return this.http.get < Organization[] > (this.baseUrl + '/list').pipe(      map(organizations => {        return organizations.filter(organization => {          organization.id === organizationId;          return {            id: organization.id,            name: organization.name,          };        });      }),    );  }  

For Eg. service returns [{1: abc, 2: def, 3: pqr}]

What I want I pass 1 as organization Id and want result [{1: abc}]

What I am getting [{1: abc, 2: def, 3: pqr}]

https://stackoverflow.com/questions/65947710/filter-result-of-observable January 29, 2021 at 09:47AM

没有评论:

发表评论