Skip to content

Instantly share code, notes, and snippets.

@whitmanc
Forked from stevenpsmith/snippet.js
Created April 30, 2012 04:42
Show Gist options
  • Save whitmanc/2555575 to your computer and use it in GitHub Desktop.
Save whitmanc/2555575 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