-
-
Save whitmanc/2555575 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exercise.ActivityListView = Backbone.View.extend({ | |
tagName: 'ul', | |
id: 'activities-list', | |
attributes: {"data-role": 'listview'}, | |
initialize: function() { | |
this.collection.bind('add', this.add, this); | |
this.template = _.template($('#activity-list-item-template').html()); | |
}, | |
render: function() { | |
var container = this.options.viewContainer, | |
activities = this.collection, | |
template = this.template, | |
listView = $(this.el); | |
$(this.el).empty(); | |
activities.each(function(activity){ | |
listView.append(template(activity.toJSON())); | |
}); | |
container.html($(this.el)); | |
container.trigger('create'); | |
return this; | |
}, | |
add: function(item) { | |
var activitiesList = $('#activities-list'), | |
template = this.template; | |
activitiesList.append(template(item.toJSON())); | |
activitiesList.listview('refresh'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment