Angular2过滤器对象数组
我将首先添加代码,我得到的结果,最后我想得到什么,如果可能的话 我得到的结果是Array[object,object,…],其中object是ArrayAngular2过滤器对象数组,angular,typescript,rxjs,reactive-programming,rxjs5,Angular,Typescript,Rxjs,Reactive Programming,Rxjs5,我将首先添加代码,我得到的结果,最后我想得到什么,如果可能的话 我得到的结果是Array[object,object,…],其中object是Array export class SomeService { .... .... public someFunction(): MyObject[]{ Observable .forkJoin(this.userItemsA(userId), this.u
export class SomeService {
....
....
public someFunction(): MyObject[]{
Observable
.forkJoin(this.userItemsA(userId), this.userItemsB(userId), etc)
.filter(each => {
for (let array of each) {
let x: any = <any> array;
return x.length > 0;
}
})
.map(result => {
return result;
})
.subscribe(result => {
/// what i would like to do for example assuming only 1st array has items
/// do something here with result[0]
/// return MyObject[] from result[0]
});
....
}
}
导出类服务{
....
....
public someFunction():MyObject[]{
可观察
.forkJoin(this.userItemsA(userId)、this.userItemsB(userId)等)
.filter(每个=>{
for(让每个的数组){
设x:any=
我正处于angular2和反应式编程的早期学习阶段,我想做的是过滤,这样映射结果将只包含至少1个项目的数组
谢谢你而不是。过滤器
使用.map
.map(each => {
return each.filter(array => array.length > 0)
}
使用.map
.map(each => {
return each.filter(array => array.length > 0)
}
不幸的是,这不适用于forkJoin
。它所做的是将多个可观察对象连接到单个可观察对象中,因此,如果其中任何一个被过滤掉,则整个连接的可观察对象将被中断/过滤
正如@Martin所说,您必须在映射
分支中进行过滤。不幸的是,这不适用于forkJoin
。它所做的是将多个观察对象连接到单个观察对象中,因此,如果其中任何一个被过滤掉,则整个连接的观察对象将被中断/过滤
正如@Martin所说,您必须在映射
分支中进行过滤。您在中的数据结构是什么。filter(each=>…
?我已经上传了过滤器的结构,thx您在中的数据结构是什么。filter(each=>…
?我已经上传了过滤器的结构,thx