【发布时间】:2017-02-01 22:08:15
【问题描述】:
阅读文档,当路径不存在时,似乎 childEventListener 不会触发。
这是一个问题,因为我想向用户显示没有数据的消息。
我可以添加一个类似in this answer 的 valueEventListener,但我将查询限制为最新值,即 query.limitToLast() 并且 valueEventListener 不限制Tolast,但会获取路径中的所有数据。
例如,我有:
posts
{
$userid
{
$postid {
post_content:content
timestamp:1234567
}
$postid {
post_content:content
timestamp:1234567
}
$postid {
post_content:content
timestamp:1234567
}
$postid {
post_content:content
timestamp:1234567
}
}
}
我只对最新的帖子感兴趣,所以我会firebaseRef.child(users).child(userid).limitToLast(1).addChildEventListener,但用户可能还没有帖子,在这种情况下不会触发 childEventListener。
【问题讨论】:
-
不确定限制值监听器的意思。如果您共享数据模型(作为 JSON 文本,没有屏幕截图)和您正在努力处理的代码,那么提供帮助会容易得多。
标签: android firebase firebase-realtime-database