通过Angular/Fire/RXJ从Firestore检索数据
我正在尝试从Firestore实例中获取收集数据,并且不想使用ValueChanges {IDField:ID}。到目前为止,这是唯一以某种方式处理某些数据并使输出接近我需要的解决方案。
我是Angular&角度/火以及RXJS,并且一般都在努力理解可观察到的,管道,地图和RXJ。
我在这里想念什么?
async fetchJobs() {
let jc = await collection(this.firestore, 'jobs');
let cSN = await collectionSnapshots(jc);
let jobsArr = cSN.pipe(
map((data) =>
data.forEach((d) => {
let jobsData = d['_document']['data']['value']['mapValue'][
'fields'
] as Job;
const newData = {
id: d.id,
title: jobsData.title,
subtitle: jobsData.subtitle,
description: jobsData.description,
publish: jobsData.publish,
img: jobsData.img,
} as Job;
return newData;
})
)
);
}
I'm trying to get collection data from a firestore instance and don't want to use valueChanges{idField: id}. So far this is the only solution that somehow processes some of the data and gets the output close to what I need.
I'm new to angular & angular/fire as well as to rxjs and am really struggling to understand observables, pipe, map and rxjs in general.
What am I missing here?
async fetchJobs() {
let jc = await collection(this.firestore, 'jobs');
let cSN = await collectionSnapshots(jc);
let jobsArr = cSN.pipe(
map((data) =>
data.forEach((d) => {
let jobsData = d['_document']['data']['value']['mapValue'][
'fields'
] as Job;
const newData = {
id: d.id,
title: jobsData.title,
subtitle: jobsData.subtitle,
description: jobsData.description,
publish: jobsData.publish,
img: jobsData.img,
} as Job;
return newData;
})
)
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该起作用。
这等同于:
由于您只需要获取作业数据,
CollectionData()
是更合适的。collectionsNapShots()
当您需要对每个作业执行其他操作(例如更新/删除每个作业)时,可能会很有趣,这是可以使用snapshot.ref.ref
示例:
这仅仅是一个例子,逻辑可能不适用于您的用例。
This should work.
which is equivalent to:
Since you only need to fetch the Job's data,
collectionData()
is way more appropriate.collectionSnapshots()
may be interesting when you need to perform additional operations on each Job, such as updating/deleting each one of them, which is possible withsnapshot.ref
Example:
This is a mere example and the logic may not apply to your use case.