简体   繁体   English

如何使用.on('child_added') 返回所有孩子?

[英]How to use .on('child_added') to return all children?

In firebase, I want to use.on('child_added') to return all children rather than returning just one children.在 firebase 中,我想使用 .on('child_added') 返回所有孩子,而不是只返回一个孩子。 I want all children after every child_added, so.once('value') is not an option.我希望每个 child_add 之后的所有孩子,所以.once('value') 不是一个选项。 How to achieve this?如何做到这一点?

For eg.例如。 In my database I have, [book1, book2, book3] as children.在我的数据库中,我有 [book1, book2, book3] 作为孩子。 When I add a new child book4, the.on('child_added') returns only {book4}.当我添加新的子 book4 时,the.on('child_added') 仅返回 {book4}。 I want it to return [book1,book2,book3,book4] Help me with this.我希望它返回 [book1,book2,book3,book4] 帮帮我。

You can use on('value') to receive updates to any child under a node.您可以使用on('value')接收节点下任何子节点的更新。 Any time anything changes under that node, it will receive a snapshot of all nested children.每当该节点下发生任何变化时,它都会收到所有嵌套子节点的快照。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM