如何将项目附加到Observable [英] How can I append items to Observable

查看:87
本文介绍了如何将项目附加到Observable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将项目附加到Observable?

这是一些代码:

 this.logEntries = this.controllerService.getLog(this.controller.remoteID, this.skip, this.max);

        this.logEntries.subscribe(a => {
            this.allLogEntries.add(this.logEntries)
        });

这是他们的声明:

 logEntries: Observable<Log[]>;
    allLogEntries: Observable<Log[]> = Observable.empty<Log[]>();

我想在从Web服务中获取项目时将其附加到allLogEntries.我该怎么办?

I want to append items to allLogEntries as they are being fetched from the web service. How do I do this?

推荐答案

也许scan运算符可能会让您感兴趣.这是一个示例:

Perhaps the scan operator could interest you. Here is a sample:

obs.startWith([])
 .scan((acc,value) => acc.concat(value))
 .subscribe((data) => {
   console.log(data);
 });

有关更多详细信息,请参见此问题:

See this question for more details:

这篇关于如何将项目附加到Observable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆