我正在寻找一种使用自定义日期范围来过滤日期的方法。 我已经在网上看到了一些在线查询日期的例子,但时间戳一直是我不能用的关键。
相关部分的文档可以在这里找到: https:/ /www.firebase/docs/web/guide/retrieving-data.html#section-queries
重要的是仍然支持实时更新。我也只想确定符合标准的所有项目的数量。我对每个节点的数据点都不感兴趣。
解决方案看起来您可以使用 orderBychild ( weight , length ),或者通过子键或属性日期)。如果你使用 startAt()& endAt(),我们可以构建您正在查找的查询:
var startDate = 14200000000; var endDate = 14300000000; ref.orderByChild(date)。startAt(startDate).endAt(endDate) .on(child_added,function(snapshot){ console.log 得到了数据!,快照); });
My firebase data looks something like this:
{ "lambeosaurus": { "date" : 1420753443, "length" : 12.5, "weight": 5000 }, "stegosaurus": { "date" : 1429053443, "length" : 9, "weight" : 2500 } }I am looking for a way to filter the dates using a custom date range. I've seen some examples online where they have queried for date, but the timestamp has always been the key which isn't possible in my case.
The relevant section is the documentation can be found here: www.firebase/docs/web/guide/retrieving-data.html#section-queries
It's important that real time updating is still supported. I also only want to determine the number of all the items that fit the criterion. I am not interested in the data point for each node.
解决方案Looks like you can use the orderBychild() method to order by child key or property (i.e. weight, length, or date). And if you chain that using startAt() & endAt(), we can construct the query you're looking for:
var startDate = 14200000000; var endDate = 14300000000; ref.orderByChild("date").startAt(startDate).endAt(endDate) .on("child_added", function(snapshot){ console.log("got the data!", snapshot); });
更多推荐
按日期范围查询Firebase
发布评论