将rxjs5运算符转换为rxjs6
我有以下代码是用rxjs5编写的,它与rxjs6不兼容 有人能帮我写RXJS6吗 其失败的mergemap接收组不可操作,该组不具有count方法,同时也不存在filter方法将rxjs5运算符转换为rxjs6,rxjs,rxjs5,rxjs6,Rxjs,Rxjs5,Rxjs6,我有以下代码是用rxjs5编写的,它与rxjs6不兼容 有人能帮我写RXJS6吗 其失败的mergemap接收组不可操作,该组不具有count方法,同时也不存在filter方法 list [ {id: '1', type: 't1', name: 'f1', des:'d1', selected: true}, {id: '2', type: 't1', name: 'f2', des:'d2', selected: false}, {id: '3', type: 't1', name
list [
{id: '1', type: 't1', name: 'f1', des:'d1', selected: true},
{id: '2', type: 't1', name: 'f2', des:'d2', selected: false},
{id: '3', type: 't1', name: 'f11', des:'d11', selected: false},
{id: '4', type: 't1', name: 'f22', des:'d22', selected: true},
]
Observable.from(list)
.filter(a => a.name != null)
.groupBy(i => i.type)
.mergeMap(list => {
let count = list.count;
let selectedCount = 0;
list.filter( f => f.selected).count.subscribe(c => selectedCount = c)
return count.map(count => {
{
key: list.key,
totalCount: count,
selected: selectedCount
}
}
}).reduce((x, y) => {
x.isValid = x.selectedCount > 0
return x;
}).subscribe(r => {
console.log(r + 'any item selected')
}
)
当我试着用rxjs6写的时候,我唯一能取得的进步就是在这里
提前谢谢
from(list)
.pipe(
filter( s=> s.name != null) ,
groupBy(i => i.type),
mergeMap( (value, index) => {
value.count // that's where it starts to fail
}
))
等效的rxjs6代码应该如下所示:
from(list)
.pipe(
filter(a => a.name != null),
groupBy(i => i.type),
mergeMap((p) => {
return p.pipe(
filter(f => f.selected),
count(),
mergeMap(c => {
return p.pipe(
count(),
map(totalCount => {
return {
key: p.key,
totalCount: totalCount,
selected: c
};
})
);
})
);
}),
reduce((x, y) => {
//please adjust your code here as i could not see isValid on x
x.isValid = x.selectedCount > 0;
return x;
})
).subscribe(r => {
console.log(r + 'any item selected')
}
)
希望它能给出一个如何继续的想法。一些执行如何不让它进入p.pipe(map(totalCount=>{return{key:p.key,totalCount:totalCount,selected:c}})你能帮我理解totalCount是从哪里来的吗?@d-man啊!我忘了使用
count
运算符。我已经编辑了我的答案。现在你应该从totalCount的来源获得答案。希望对你有所帮助。