0

The firebase documentation here (https://github.com/firebase/backfire#backbonefirebasecollection) mentions that you can apply a limit to a Backbone.Firebase.Collection:

var Messages = Backbone.Firebase.Collection.extend({
  firebase: new Firebase("https://<your-firebase>.firebaseio.com").limit(10)
});

I would like to make that limit a variable - so I could sometimes show 10 records from the collection and sometimes 100 (as an example).

Can anyone recommend the best way to achieve this?

dtt101
  • 2,151
  • 25
  • 21
  • 1
    Your best bet in this case would be simply create a new collection with the new limit. It's not easy to dynamically change limits once they've been applied to a Firebase reference. – Anant Jan 30 '14 at 19:51
  • Thanks for the advice @Anant - I think I will instead just not use the backbone integration to retrieve the records - appreciate the feedback though! – dtt101 Feb 02 '14 at 19:06
  • I'd love to see this feature implemented in Firebase. You basically can't do infinite pagination without unnecessarily re-requesting and redrawing elements that haven't really changed -- unless there's a way to assign a new firebase reference to an existing collection, that is. – Dany Joumaa Apr 24 '14 at 18:02

1 Answers1

0

Firebase now supports query limits, using limitToFirst or limitToLast

The following code would get the first 2 records.

var ref = new Firebase("https://dinosaur-facts.firebaseio.com/"); ref.orderByChild("height").limitToFirst(2).on("child_added", function(snapshot) { console.log(snapshot.key()); });

More info in the docs: https://www.firebase.com/docs/web/api/query/limittofirst.html

dtt101
  • 2,151
  • 25
  • 21