Reputation: 43
I have an app that can load more items when user scrolled at the bottom, I'm thinking one way to handle this is to adjust limitToLast dynamically so the child_added event will get triggered again.
Can I do this without having to rebind my .on() functions?
Upvotes: 1
Views: 1110
Reputation: 1
function doDynamic(offset){
ref.orderByChild("foo").limitToLast(1 * offset).once('value', function (snap) {
//do stuff
})
}
Upvotes: 0
Reputation: 599686
If you have a query like this:
var query = ref.orderByKey().limitToLast(10)
And you want to change the number of items shown, you will have to create a new query:
var query = ref.orderByKey().limitToLast(25)
However: if you're just looking to pick up new items that are added to Firebase, that will happen automatically.
An example may clarify this. Say that you start with a list of 10 items:
-Jy39378901
-Jy39378902
-Jy39378903
-Jy39378904
-Jy39378905
-Jy39378906
-Jy39378907
-Jy39378908
-Jy39378909
-Jy39378910
With the first query above, you will initially get 10 child_added
events.
Now if someone later adds an item -Jy39378911
to this list, you will get two events:
child_removed: -Jy39378900
child_added : -Jy39378910
So new items show up automatically. But changing the query parameters is not possible, unless you create a new query.
Upvotes: 1