I'm new to all the backend side of things, so hopefully this is one of the questions I'm gonna look back to and think "man, that was silly of me". Let me start. I want to make an application where you can draw rectangles on a screen.
Every rectangle is a model represented by an ItemView
and every screen is a collection represented by a CollectionView
. Rectangles are added to the collection once they are created by the user, dynamically.
When the user clicks on a "new screen" button, the following takes place
MyController = Backbone.Marionette.Controller.extend({
initialize:function() {
i=0;
},
newScreen: function() {
i=i+1;
this.collection = new Rectangles([],{id: i});
routestring = "screen/"+i;
router.navigate(routestring);
canvas.show(new ScreenView({collection: this.collection}));
},
...
I use an iterator for the different screens so that my backend looks like this
demo.firebaseio.com/screens/1
I am using Firebase's backbone bindings but I have absolutely no idea on how I can access a collection that's already stored on the server. The reason is that I want to be able to navigate through the different screens, fetch the collection from that url, and render it...
Here's my collection code
Rectangles = Backbone.Collection.extend({
initialize: function(models, options) {
this.id = options.id;
},
url: function() {
return 'https://demo.firebaseio.com/screen/'+this.id;
},
model: Rectangle,
firebase: function() {
return new Backbone.Firebase("https://demo.firebaseio.com/screen/"+this.id)
}
});
and here's my router code!
var Router = Backbone.Marionette.AppRouter.extend({
controller: myController,
appRoutes: {
'': 'newScreen',
'screen/:number': 'doSomething'
}
})
I'm open to any suggestions, and I do understand that I might have done something horribly wrong!