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

查看:23
本文介绍了如何将项目附加到 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[]>();

我想将项目附加到 allLogEntries,因为它们是从 Web 服务获取的.我该怎么做?

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天全站免登陆