【发布时间】:2020-11-05 06:49:38
【问题描述】:
我对 Observables 和 rxjs 的整个概念很陌生,所以这可能非常明显。但是请帮忙,因为我很想学习
当用户在博客文章下点击显示 cmets 时,我有一个功能
showComments(){
this.firestoreservice.getComments(this.job.id).subscribe( data =>{
this.comments = data //type [] of comment objects with (message,posterID,timeposted...)
})
this._showcomments = true;
}
此函数调用一个服务函数,该函数将一个可观察对象返回到该作业的我的 cmets 列表中。 在订阅那个 observable 时初始化一个变量来保存我所有的 cmets。 但是,在我这样做之前,有没有办法用匹配的用户名替换每个评论的 posterID 属性?请参阅下面的预期结果:
showComments(){
this.firestoreservice.getComments(this.job.id).subscribe( data =>{
//for each comment held in data, replace comment.posterID with getUserName(posterID)
//getUserName(posterID) will also return an observable which emmits one string
//then append comment to comments list (or add back in to data then destructively assign
//comments=data )
this.comments = data //type [] of comment objects with (message,posterID,timeposted...)
})
this._showcomments = true;
}
【问题讨论】:
标签: angularjs rxjs observable angularfire rxjs-observables