有效地获取数组 BehaviorSubjects 的 Observable [英] Efficiently get Observable of an array BehaviorSubjects

查看:50
本文介绍了有效地获取数组 BehaviorSubjects 的 Observable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个字段:

smartArray: BehaviorSubject<BehaviorSubject<object>[]>; 
//Example
[{key1: 'value1', key2: value2},...]; 

我现在想获取并订阅其中一个属性:

I now want to get and subscribe to one of the properties:

getObeservablePropertyOfSmartArray(index, property){
   return this.smartArray.pipe(
         //...getelementAtIndex <---dont know how
         //lets say the elementatIndex is elem: 
         elem.pipe(
         //get the property and return the Observable

         )).asObservable(); 
}

所以我基本上需要array[index] 和object[key] 的等价物,并为BehaviorSubjects 返回Obeservable.我怎样才能做到这一点?

So I basically need the equivalent of array[index] and object[key] and return Obeservable for BehaviorSubjects. How can I do that?

推荐答案

你可以使用mergeMap切换到索引上的那个observable,然后你可以使用map来获取你想要的属性值我在这里为你做了例子:https://stackblitz.com/edit/angular-qzeuzt

you can use mergeMap to switch to that observable on the index, then you can use map to get the property value that you want I made example for you here: https://stackblitz.com/edit/angular-qzeuzt

这篇关于有效地获取数组 BehaviorSubjects 的 Observable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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