在Angular RXJS中添加可观察到的可观察返回的部分数据
在我的代码中,我需要使用计时器(500)添加延迟。但是问题是它返回部分数据。它正在返回2个字段,而实际数据有17个字段。我附上了代码。请看看。谢谢
返回的价值:
['booking_display_id', 'edit']
期望值:
['booking_display_id', 'bookingstatus', 'b_contactname', 'member', 'b_emailaddress', 'b_mobilenumber', 'startdate', 'enddate', 'duration', 'bookingguest', 'guestnotes', 'vouchers', 'paypalpaymentpdt', 'totalCost', 'canPay', 'canCancel', 'edit']
this.displayedColumns = combineLatest(this.table.columns.reduce((observables: Observable<boolean>[], col) => {
// handle showIf property of column
const show = col.showIf(this.injector, this.route.queryParamMap);
observables.push(show instanceof Observable ? show : of(show));
return observables;
}, []), timer(500)).pipe(
map(showCols => {
const cols = this.table.columns.filter((c, i) => showCols[i])
.map(c => c.id);
this.editEnabled && cols.push('edit');
this.deleteEnabled && cols.push('delete');
console.log('cols', cols)
return cols;
})
);
In my code I need to add delay by using timer(500). But the issue is that it returns partial data. It is returning 2 fields while actual data has 17 fields. I have attached my code. please see it. Thank you
Returned value:
['booking_display_id', 'edit']
Expected value:
['booking_display_id', 'bookingstatus', 'b_contactname', 'member', 'b_emailaddress', 'b_mobilenumber', 'startdate', 'enddate', 'duration', 'bookingguest', 'guestnotes', 'vouchers', 'paypalpaymentpdt', 'totalCost', 'canPay', 'canCancel', 'edit']
this.displayedColumns = combineLatest(this.table.columns.reduce((observables: Observable<boolean>[], col) => {
// handle showIf property of column
const show = col.showIf(this.injector, this.route.queryParamMap);
observables.push(show instanceof Observable ? show : of(show));
return observables;
}, []), timer(500)).pipe(
map(showCols => {
const cols = this.table.columns.filter((c, i) => showCols[i])
.map(c => c.id);
this.editEnabled && cols.push('edit');
this.deleteEnabled && cols.push('delete');
console.log('cols', cols)
return cols;
})
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题是,您通过了一系列可观察到的东西,以及另一个可观察到的combineLatest。但是,它只需要一系列可观察到的(1维数组)。因此,您需要用另一个
combineLatest
包裹您的减少,或者将它们传播(=&gt;[... obs,timer]
obs obs将是您的降低)。这是您简化的当前调用,
我建议您使用传播操作员构建一个新数组,或者您可以使用另一个
combineLatest
,因为它是另一个可观察到的数组。另外,我建议您使用
delay
而不是计时器
(如果您希望将值与计时器分开, 则仅运行一次)
bombineLatest([combineLatest(.. obs),计时器])
如果您不希望将值与计时器分开
CombineLatest([.. obs,timer])
Your issue is that you pass an array of observables as well as another observable to the combineLatest. However it only takes an array of observables (1dimensional array). Therefor you need to either wrap your reduce with another
combineLatest
or spread them ( =>[...obs, timer]
obs would be your reduce) into one array.This is your simplified current call
I would recommend you use the spread operator to build a new array like so or you can use another
combineLatest
since it is another array of observables.Also I recommend that you use
delay
instead oftimer
(delay runs only once)If you want your values to be separated from the timer
combineLatest([combineLatest(..obs), timer])
If you do not want your values to be separated from the timer
combineLatest([..obs, timer])