【发布时间】:2017-06-24 15:54:56
【问题描述】:
假设我有一个函数,它返回下面对象ObjectReturned 的Observable:
interface ObjectReturned {
id: string,
information: info[],
anotherObj: AnotherObj[]
}
interface AnotherObj {
information: info[]
}
interface info {
name: string
}
鉴于ObjectReturned.info[] 和AnotherObj.info[] 都每个都只包含一个元素,我如何使用Observable 的map 运算符来“展平”上面的info 数组这样我就可以直接使用objectReturned.name 和objectReturned.anotherObj.name 访问返回的结果(Observable<ObjectReturned>)?
【问题讨论】:
-
observable 与此无关。只需使用地图,然后自己将其展平。
const [firstAndOnlyValue] = yourArray;然后根据需要使用 firstAndOnlyValue -
可能我没说清楚,抱歉,我还是想返回一个
ObjectReturned的 observable
标签: rxjs observable rxjs5