2017-10-14 32 views
0

的水平我有以下JSON:RxJS:JSON移動對象屬性下面

enter image description here

apps是對象的數組。 apps數組在另一個包裝它的json對象內。我創建了下面的方法返回應用程序列表:

return this.http.get(`analytics`) 
     .map((data: any) => { return data.apps; }); 

現在,你可以在截圖中看到,有一個bandwidth對象與total屬性。我需要的total財產移動bandwidth內物體內部是在應用程序列表中的第一級:

enter image description here

我怎樣才能做到這一點使用RxJS?

+0

您是否嘗試過任何方法? –

+0

RxJS允許處理流。由於數據是一個常規對象,因此您可以像處理常規對象一樣處理它 – estus

回答

2

試試這個:

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; 
      }); 
     });