Skip to content

Instantly share code, notes, and snippets.

@julesbou
Created March 11, 2016 15:33
Show Gist options
  • Save julesbou/66133708c1d63949e562 to your computer and use it in GitHub Desktop.
Save julesbou/66133708c1d63949e562 to your computer and use it in GitHub Desktop.
var Router = Backbone.Router.extend({
init: function() {
this.views = [];
},
routes: {
'load/:index': 'loadView'
},
instanciateView: function(index) {
var model = new Backbone.Model({
index: parseInt(index, 10),
name: 'view' + index
});
// just creating a view
return new View({ model: model });
},
loadView: function(index) {
var view = this.instanciateView(index);
// store view in an array to access it later
this.views.push(view);
// (tip) problem is in line below
$('#app').html(view.render().$el);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment