gpt4 book ai didi

ios - 如何更新 Firebase-Database 树中的最新条目?

转载 作者:行者123 更新时间:2023-11-28 14:37:30 25 4
gpt4 key购买 nike

我想更新(或同步)我的 Firebase 数据库中树的最新条目。

结构如下:

我只想观察最新的条目,而不像“EventTypeChildAdded”那样获取所有条目。
但是,我真的很想观察最新的条目,所以我想在有新的“最新”条目时调用一个函数,所以当一个 child 被添加时。

我已经找到了这段代码。

(DatabaseRef).queryOrderedByKey().queryLimitedToLast(1).observeSingleEventOfType

但是这个好像没有观察到最新的条目。

最佳答案

我猜你走错了路。 childadded 正是您所需要的。再次检查文档。 https://firebase.google.com/docs/database/admin/retrieve-data#child-added

childadded 第一次获取所有列表,但随后仅获取刚刚添加到列表中的项目。

Child Added

The child_added event is typically used when retrieving a list of items from the database. Unlike value which returns the entire contents of the location, child_added is triggered once for each existing child and then again every time a new child is added to the specified path. The event callback is passed a snapshot containing the new child's data. For ordering purposes, it is also passed a second argument containing the key of the previous child.

编辑:将 childadded 查询限制为最后一项:

ref.queryLimited(toLast: 1).observe(.childAdded) { (snapshot) in
// parse snapshot to get the last item

关于ios - 如何更新 Firebase-Database 树中的最新条目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50766151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com