我想在用户的通知上放置一个侦听器,并且每次我想将 show 属性设置为 (true),但问题是每次更新时 onSnapshot 侦听器都会被触发并执行一些问题。 这是我的代码:
db.collection("members")
.doc(loggedUser.uid)
.collection("notifications")
.onSnapshot(snapshot => {
const unShowedNoti = snapshot.docs
.map(doc => ({ body: doc.data(), ref: doc.ref }))
.filter(doc => !doc.body.show)
unShowedNoti.forEach(alert => {
// fire an alert
})
// update show to true
unShowedNoti.forEach(alert => {
// update show alert
})
})