离子可观察采集嵌套属性

时间:2018-05-16 13:00:30

标签: javascript angular ionic-framework rxjs observable

我正在使用Ionic和一个Observable httpClient请求,并希望使用pluck()以我需要的格式获取数据。我从某个格式的Google Place api调用中获得了json输出。

api输出格式:

Select kunnr, altkn, bukrs from kna1 as outer_kna1 
   inner join outer_knb1 on outer_kna1~kunnr = outer_knb1~kunnr "added join
   where exists (
      "what you select here doesn't matter
      Select kna1~kunnr from kna1 inner join knb1 on kna1~kunnr = knb1~kunnr 
      where kna1~kunnr = outer_kna1~kunnr
      and altkn = outer_knb1~altkn and bukrs = outer_knb1~bukrs "added conditions
      group by ALTKN, BUKRS "Keys, by which duplicates are searched for
      having count( * ) > 1 "Condition to only select duplicates (in this case, record count in a group is more than 1)
   )
into table @lt_duplicate_account_data.

所需格式:

{
  "html_attributions" : [],
  "next_page_token" : ...,
  "status" : "OK",
  "results" : [
      {
      "geometry" : {
        "location" : {
          "lat" : 52.693031,
          "lng" : -2.53443
        }
      },
      ...
    },
    {
      "geometry" : {
        "location" : {
          "lat" : 52.3841398,
          "lng" : -2.3740612
        }
      },
      ...
    },
  ]
}

我读到here,这应该可以在嵌套属性上使用 [ { "location" : { "lat" : 52.693031, "lng" : -2.53443 } }, { "location" : { "lat" : 52.693031, "lng" : -2.53443 } }, ... ]

我正在尝试的片段:

pluck()

它似乎只能拔出第一级而不是下一级。任何人都可以表明我做错了什么。

1 个答案:

答案 0 :(得分:1)

您可以使用rxjs maparray map

获得所需的格式
this.places
.pipe(
  map(places => places.results.map(result => result.geometry))
)