如何将两个对象与rxjs组合起来 例如,我有
const users$ = Rx.Observable.of([
{id: 1, name: 'Arthur', lang: 'en'},
{id: 2, name: 'Asset', lang: 'ru'},
{id: 3, name: 'Steve', lang: 'en'}
])
const months$ = Rx.Observable.of({
ru: ['Январь', 'Февраль'],
en: ['January', 'February']
})
必须在输出
[
{
months: ['Январь', 'Февраль']
user: 'Asset
}
{
months: ['January', 'February']
user: 'Arthur
}
{
months: ['January', 'February']
user: 'Steve
}
]
我们必须只使用rxjs
答案 0 :(得分:1)
这更像是一个数组操作,不需要真正使用rxjs
Observable.zip(users$,month$).map(([users,months])=>
users.reduce((acc,curr)=>{
acc.push({user:curr.name,month:months[curr.lang]})
return acc;
},[])
).subscribe()