Backbone: Inserting Collection Just Once
How many times is the Collection View below writing to the DOM: once for
the entire Collection, or once for each item in the Collection?
If it is writing multiple times, is there a way to store the Views and
then append them all at once?
App.Views.Tasks = Backbone.View.extend({
tagName: 'ul',
initialize: function() {
this.render();
},
render: function() {
this.collection.each(this.addOne, this);
return this;
},
addOne: function(task) {
var taskView = new App.Views.Task({ model: task });
this.$el.append(taskView.render().el);
}
});
var tasksCollection = new App.Collections.Tasks([
{{a bunch of tasks}}
]);
var tasksView = new App.Views.Tasks({ collection: tasksCollection });
$(.tasks).html(tasksView.render().el);
No comments:
Post a Comment