Skip to content

Instantly share code, notes, and snippets.

@stevenpsmith
Created December 22, 2011 17:37
Show Gist options
  • Save stevenpsmith/1511141 to your computer and use it in GitHub Desktop.
Save stevenpsmith/1511141 to your computer and use it in GitHub Desktop.
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