Skip to content

Instantly share code, notes, and snippets.

@rondorkerin
Created March 5, 2014 22:23
Show Gist options
  • Save rondorkerin/9377922 to your computer and use it in GitHub Desktop.
Save rondorkerin/9377922 to your computer and use it in GitHub Desktop.
A Backbone.js Router
$(function() {
var goals = new GoalCollection([]);
console.log(goals.url);
var goalCategoryView = null;
var Router = Backbone.Router.extend({
routes: {
":category": "category",
},
category: function(category) {
if (goalCategoryView) {
goalCategoryView.remove();
}
$('#goalCategory').append('<div></div>');
var child = $('#goalCategory').children();
goalCategoryView = new GoalView.GoalCategory({
el: child,
model: {
title: category, // TODO: uppercase this
category: category,
imageUrl: 'images/' + category + '.png'
},
collection: goals
})
goalCategoryView.render();
},
});
var router = new Router();
Backbone.history.start();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment