1

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!

David East
  • 31,526
  • 6
  • 67
  • 82
  • 1
    Without seeing your code, it's tricky to help. See [MCVE](http://stackoverflow.com/help/mcve). – Frank van Puffelen Mar 15 '16 at 16:44
  • *"how to change the month and trigger everything updating. eg if I hardcode my url it's something like"* - change month in the application or firebase..? hardcode something in application or firebase..? Your question isn't clear try to rephrase it... – T J Mar 16 '16 at 05:08

1 Answers1

0

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)'
});
David East
  • 31,526
  • 6
  • 67
  • 82
  • I like the look of this. Struggling to get it to work as it's complaining the model must have an ID. Fairly sure a more careful read of the docs will help me. – user3728926 Mar 16 '16 at 22:47