Reputation: 11
I'm creating a backbone application that is divided into months. In my firebase the month is the parent node, and under that I have key\value pairs that I need.
What I can't figure out is how to change the month and trigger everything updating. eg if I hardcode my url it's something like
https://blinding-fire-XXXX.firebaseio.com/Application/Month1
which is fine for getting data for Month1 , but how should I update my application to get data for Month2?
I'm assuming I should be able to use the base url (without Month1) and some sort of filter, but I just can't figure it out.
I have tried , 'restarting' the app when the user selects a different Month and this works the first time a month is shown, but if they return to a previously selected month , I get an empty list.
Hoping someone can point me in the right direction!
Upvotes: 1
Views: 64
Reputation: 32604
You can use the urlRoot
property to create a new Firebase.Model
based on the base url and the model's id
.
var Month = Backbone.Firebase.Model.extend({
urlRoot: 'https://<my-firebase>.firebaseio.com/Application/'
});
// The url for this model is https://<my-firebase-app>.firebaseio.com/Application/Month1
var month = new Month({
id: "Month1"
});
month.on('sync', function(model) {
console.log('Model loaded');
console.log(model)'
});
Upvotes: 0