我想过滤一个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
完成它答案 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;
});