gpt4 book ai didi

javascript - 如何过滤BehaviorSubject数组

转载 作者:行者123 更新时间:2023-12-02 22:56:11 25 4
gpt4 key购买 nike

我想过滤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来完成它

最佳答案

试试这个。

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

关于javascript - 如何过滤BehaviorSubject数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57967206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com