如何过滤BehaviorSubject数组

时间:2019-09-17 04:06:18

标签: javascript angular rxjs

我想过滤一个BehaviorSubject类型的数组,并更新该数组的对象属性之一的值。

public users$: BehaviorSubject<IUser[]> = new BehaviorSubject<IUser[]>([]);

 {
        [key:'id',username:'John'],
        [key:'id',username:'David'],
        [key:'id',username:'Sara']
}
this.breadcrumbs$
            .pipe(
                map(user=> from(user)
                    .pipe(first(x => x.key === key)))
            ).subscribe(res => {
                   const index = this.usersValue.indexOf(res);
                   this.usersValue[index]['username'] = label;
});

我想用 rxjs

完成它

1 个答案:

答案 0 :(得分:1)

尝试这个。

this.breadcrumbs$.pipe(
   map(users => users.find(user => user.key === key)))
   .subscribe(res => {
       const index = this.usersValue.indexOf(res);
       this.usersValue[index]['username'] = label;
   });