Here's my code. Feel free to tell me what I'm doing wrong or right. I'm trying to store everything in the PhishVids object. If this is the wrong way to do things, please let me know.
My JSON is stored in /shows/YEAR.json. The years range from 1987-2011. I can't seem to get the JSON loaded in, so can anyone point me in the right direction?
var PhishVids = {
Models: {
Show: Backbone.Model.extend({
defaults: {
showid: 'show id',
year: 'year',
month: 'month',
day: 'day',
venue: 'venue'
}
})
},
Views: {
Show: Backbone.View.extend({
el: $('#content'),
initialize: function() {
this.model.fetch();
this.model.bind('change', this.render, this);
},
render: function(event) {
var compiled_template = _.template($("#shows-template").html());
this.el.html(compiled_template(this.model.toJSON()));
return this; //recommended as this enables calls to be chained.
},
events: {
"click .show": "showClick"
},
showClick: function(event) {
}
})
},
Collections: {
ShowList: Backbone.Collection.extend({
parse: function(response) {
return response.items;
}
})
}
};
Show Template:
<script type="text/template" id="shows_template">
<a href='/<%= year %>/<%= month %>/<%= day %>' class='show <%= month %> <%= day %>' id='<%= showid %>'><%= month %>/<%= day %></a>
<div class='venue'><%= venue %></div>
</script>
#shows-templateand in template the id isshow_template.