My Backbone app is going to have multiple objects of a Collection, each collection containing multiple models. What I'd like to do is to have each Collection object wrapped into a div element, and a custom title depending on the collection object attribute value.
At the moment Collection is utilizing views for the models and doesn't contain any of its own template.
What would be the best approach to wrap each collection object into a template?
Update:
Here is how my CollectionView looks like at the moment:
window.OrderListView = Backbone.View.extend({
el: '#all-orders-container',
template: _.template(orderListTpl),
initialize: function() {
this.$el.append(this.template({order_id: this.collection.order_id}));
},
render: function(){
var _this = this;
this.collection.forEach(this.addItem, this);
},
addItem: function(orderItem){
var orderView = new OrderView({
model: orderItem
});
this.$el.append(orderView.render());
}
});
There will be multiple objects of the same CollectionView class. The problem now is - how to render those into a separate elements, and also append new orderView elements into a proper elements?