secret
anonymous / index.js
Created

backbone collection can't fetch

  • Download Gist
index.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
var schools;
schools = new window.schools;
schools.fetch();
/* response: [{"name":"Foo"},{"name":"Bar"}] */
/* schools.length => 0 */
debugger
window.fooView = Backbone.View.extend({
el: $("#bar"),
initialize: function() {
/* this never fires */
debugger;
return schools.bind('all', this.render);
},
render: function() {
var htmlList, listTemplate;
listTemplate = _.template('<li><a href="/<% name.escape %>"><%= name %></a></li> ');
htmlList = '';
console.log(schools);
debugger;
schools.each(function(school) {
console.log(school);
htmlList += listTemplate({
name: school.get('name')
});
console.log(school.get("name"));
return console.log(htmlList);
});
return $('#bar').html(htmlList);
}
});
router.js
JavaScript
1 2 3 4 5 6 7 8 9 10
window.application = Backbone.Router.extend({
routes: {
"": "index",
":school/places": "places"
},
index: function() {
return new window.fooView;
},
places: function(school) {}
});
school.js
JavaScript
1
window.school = Backbone.Model.extend({});
school_collection.js
JavaScript
1 2 3 4
window.schools = Backbone.Collection.extend({
url: '/schools',
model: window.school
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.