Angularfire - Firebase query / sync first x items in document

梦想的初衷 提交于 2019-12-02 08:23:06

The first parameter passed into startAt is a priority, not a record key. Since it doesn't look like you need a key or a priority in this case, you can simply this syntax to snag the first three items:

new Firebase(URL).startAt().limit(3)

Additionally, the "id" stored in each record of the example data is not the key for that record, it's just another field in the data and might as well be "foo" or any other arbitrary moniker, as far as querying is concerned.

When these records get stored in Firebase, the array is converted to an object, and the indices are used as the keys for each entry. So the first record's id would be 0, not 1. So if I wanted to grab the second through fourth records (e.g. 1 through 3 as you attempted), I could do this:

new Firebase(URL).startAt(null, 1).limit(3)

Please have a thorough read of the lists of data doc and our blog on array best practices; most of the time, you'll want to avoid those and use unique ids.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!