Skip to content

Instantly share code, notes, and snippets.

@Pickra
Created October 1, 2013 13:57
Show Gist options
  • Save Pickra/6778831 to your computer and use it in GitHub Desktop.
Save Pickra/6778831 to your computer and use it in GitHub Desktop.
mason, made it go. but i didnt set this up the best way.
StudentRouter = Backbone.Router.extend({
initialize: function(){
this.students = new StudentCollection()
this.students.add(studentData)
},
routes: {
/* router is listening for these events. when i click on the "all" <a>,
the 'all' function happens */
// " " : 'all',
"all/edit/:id" : "edit",
"all" : "all",
"all/:id" : "single",
"create" : "create"
},
all: function(){
$('.container').html('')
// stole from allison, but dsnt wrk ---- look at jquery api site for the below
// $.getJSON('http://0.0.0.0:3000/collections/students', function(arg){
// this.students = new StudentCollection()
// this.students.add(studentData)
// })
console.log(studentData)
console.log(this.students)
this.students.each(function(student){
new RowsView({model: student})
})
},
single: function(id){
$('.container').html('')
var thatStudent = this.students.get(id);
new SingleView({model: thatStudent});
console.log('show an item w/ id', id)
},
edit: function(id){
$('.container').html('')
new EditView({model:this.students.get(id)})
},
create: function(){
var student = new Student();
this.students.add(student)
$('.container').html('')
new CreateView({model: student});
// this.students.add(new obj?)
}
});
$.getJSON('http://0.0.0.0:3000/collections/students').done( function(data){
// console.log('data',data)
studentData = data
studentrrrouter = new StudentRouter()
Backbone.history.start()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment