Created
September 20, 2012 06:05
-
-
Save swallentin/3754207 to your computer and use it in GitHub Desktop.
Backbone.js Router Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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