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 31 32 33 34 35 36 37 38 39 40 41
|
// Category View
// =============
// Includes file dependencies
define([
"jquery",
"backbone",
"../models/CategoryModel"
], function( $, Backbone, CategoryModel ) {
// Extends Backbone.View
var CategoryView = Backbone.View.extend( {
// The View Constructor
initialize: function() {
// The render method is called when Category Models are added to the Collection
this.collection.on( "added", this.render, this );
},
// Renders all of the Category models on the UI
render: function() {
// Sets the view's template property
this.template = _.template( $( "script#categoryItems" ).html(), { "collection": this.collection } );
// Renders the view's template inside of the current listview element
this.$el.find("ul").html(this.template);
// Maintains chainability
return this;
}
} );
// Returns the View class
return CategoryView;
} );
|