检索具有一系列数据的可观察
想象一下,我有一系列可观察的物品,在这一可观察到的阵列中,我还有其他参考阵列,我希望能够检索具有参考阵列数组的可观察到的可观察到的东西,我有点粘在它上几天,还有其他方法吗?
export class ReferenceData {
id: number;
caption: string;
constructor(_id: number, _caption: string) {
this.id = _id
this.caption = _caption
}
}
const observables = [
of([new ReferenceData(1, 'Test'), new ReferenceData(2, 'Test 2')]),
];
const getData = (): Observable<[ReferenceData[]]> {
return observables.map((obs) => {
return obs.pipe(
map((data) => {
return [...data]
})
)
})
}
从getData函数中预期的返回:可观察的&lt; [referenceedata []]&gt;
Imagine, I have an array of observables, inside this array of observables I have other arrays of ReferenceData, I want to be able to retrieve an Observable with an Array of ReferenceData arrays, I'm a bit stuck on it for a couple of days, is there any other way to do that?
export class ReferenceData {
id: number;
caption: string;
constructor(_id: number, _caption: string) {
this.id = _id
this.caption = _caption
}
}
const observables = [
of([new ReferenceData(1, 'Test'), new ReferenceData(2, 'Test 2')]),
];
const getData = (): Observable<[ReferenceData[]]> {
return observables.map((obs) => {
return obs.pipe(
map((data) => {
return [...data]
})
)
})
}
Return expected from getData function: Observable<[ReferenceData[]]>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用如下: -
You can use forkJoin operator like below :-