RxJS:JSON移动对象属性下面
问题描述:
的水平我有以下JSON:RxJS:JSON移动对象属性下面
我apps
是对象的数组。 apps
数组在另一个包装它的json对象内。我创建了下面的方法返回应用程序列表:
return this.http.get(`analytics`)
.map((data: any) => { return data.apps; });
现在,你可以在截图中看到,有一个bandwidth
对象与total
属性。我需要的total
财产移动bandwidth
内物体内部是在应用程序列表中的第一级:
我怎样才能做到这一点使用RxJS?
答
试试这个:
return this.http.get(`analytics`)
.map((data: any) => {
return data.apps.map((app)=>{
if(app.bandwidth && app.bandwidth.total){
app.total = app.bandwidth.total;
delete app.bandwidth.total;
}
return app;
});
});
您是否尝试过任何方法? –
RxJS允许处理流。由于数据是一个常规对象,因此您可以像处理常规对象一样处理它 – estus