The next step will be to display the list of podcasts that the user is subscribed to. We start with the PodcastListView
class, which will display the collection. Here's that class:
var PodcastListView = Backbone.View.extend({ className: 'list-group', initialize: function (options) { this.current = options.current || null; this.listenTo(this.collection, 'add', this.render); }, render: function () { if (this.collection.length === 0) { this.el.innerHTML = "<a class='list-group-item'>No Podcasts</a>"; return this; } this.el.innerHTML = ''; this.collection.forEach(this.renderItem, this); return this; }, renderItem: function (model) { model.set({ current: this.current === model.get('id') }); var v = new PodcastListItemView({ model: model }); this.el.appendChild(v.render().el); } });
For Bootstrap, we'll add the list-group
class to the view's element. In the initialize
method, we'll check the options...