接收新推孩子的通知 [英] Receive notifications of newly pushed children

查看:69
本文介绍了接收新推孩子的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在.push()进入firebase引用.

I'm .push() ing into a firebase reference.

我希望侦听器能够联机,然后仅通知刚.push()个孩子.

I want a listener to be able to come online, and then be notified only of newly .push() ed children.

因此,如果该节点已经包含5个子节点,并且客户端来了并希望收到新的子节点的通知,并且推送了2个,则该客户端应该只收到2个通知.

So if the node already contains 5 children and client comes and wishes to be notified of new children, and 2 are pushed, then the client should only receive 2 notifications.

现在,.on('child_added',function...)联机时,客户端不仅会收到新消息,还会收到所有旧消息.这是我要避免的第二部分.

Right now with .on('child_added',function...) when coming online, the client receives not only new messages, but also all the old messages. It's that second part I want to avoid.

我也尝试过使用.startAt().limit(1)...,但这似乎也没有达到预期的效果.我不确定它到底在做什么,但肯定不是我所期望的.

I have also tried using .startAt().limit(1)..., but this doesn't seem to behave as desired either. I am not sure what exactly it is doing with that, but certainly not what I expect.

推荐答案

startAt()返回最早的(第一条)记录,其中endAt()还原最新的(最新)记录,假设您已使用push()进行存储他们.

startAt() returns the oldest (first) records, where endAt() returs the last (newest) records, assuming you've used push() to store them.

因此,这将为您提供最新的条目:

So this would give you the newest entries:

 ref.endAt().limit(1)

请记住,您收到的第一条记录是先前存在的,因此,在只有用户上线后才添加的数据才有价值的用例中,应将其丢弃.

Keep in mind that the first record you receive will be previously existing, so it should be discarded in the use case that only data added after a user comes online is of value.

这篇关于接收新推孩子的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆