Skip to content

Instantly share code, notes, and snippets.

@swallentin
Created September 20, 2012 06:05
Show Gist options
  • Save swallentin/3754207 to your computer and use it in GitHub Desktop.
Save swallentin/3754207 to your computer and use it in GitHub Desktop.
Backbone.js Router Template
var AppRouter = Backbone.Router.extend({
vent: _.extend({}, Backbone.Events),
routes: {
// TODO: index should games-list
"game/:id": "game",
"": "index"
},
index: function() {
var myGames = new Games();
myGames.fetch({
success: function() {
var gameListView = new GameListView({
collection: myGames
});
$("#game").html(gameListView.render().el);
}
});
},
game: function(id) {
var self = this;
var game = new Game({
_id: id
});
game.fetch({
success: function(model, response) {
var gameView = new GameView({
el: $("#game"),
vent: self.vent,
model: model
});
$("#game").html(gameView.render().el);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment