可以映射到另一个映射结果rxjs吗?

时间:2019-10-02 07:37:52

标签: dictionary rxjs pipe observable angular7

我正在使用angular 7,并且在理解管道语法的工作方式时遇到了一些问题。

到目前为止,这是我的代码:

    tests: Row[]
    public getTest() : Observable<Row[]> {
      return this.http.get<Test[]>(this.testUrl)
      .pipe(
        map((tests) => {
          tests.map(test => test.rows = this.tests)
          return this.tests;
    }))
  }

这是我的模特:

export interface Test {
  total_rows: number;
  offset: number;
  rows: Row[];
}

export interface Row {
  id: string;
  key: Key;
  value?: any;
}

export interface Key {
  name: string;
}

这是JSON:

{
  "total_rows": 2,
  "offset": 0,
  "rows": [
    {
      "id": "54229d6897e1d1c7d603428a850081d5",
      "key": {
        "name": "test1"
      },
      "value": null
    },
    {
      "id": "54229d6897e1d1c7d603428a85010e03",
      "key": {
        "name": "test2"
      },
      "value": null
    }
  ]
}

我想获取的数据是:行的数组

谢谢您的帮助

1 个答案:

答案 0 :(得分:0)

在您的示例中,一种方法属于Observal.map(),另一种方法是原始本机Javascript's array .map()

不确定要实现的目标,如果只想检索Rows数组并将其分配给this.tests,则可以使用{{1 }},而无需使用JS数组Observable。记住订阅您的可观察内容:

Observable.map()