Problem
Using a Backbone.Marrionette.Layout to present some tabular data. The
Marionette 3 deprecated the See this example to render a table: portion of the table is a Backbone.Marionette.R
CompositeView
class. Instead, a region can now overwrite its el
with the rendered contents of the
inner View with the new replaceElement option.var RowView = Marionette.View.extend({
tagName: 'tr',
template: '#row-template'
});
var TableBody = Marionette.CollectionView.extend({
tagName: 'tbody',
childView: RowView
});
var TableView = Marionette.View.extend({
tagName: 'table',
className: 'table table-hover',
template: '#table',
regions: {
body: {
el: 'tbody',
replaceElement: true
}
},
onRender: function() {
this.showChildView('body', new TableBody({
collection: this.collection
}));
}
});
var list = new Backbone.Collection([
{id: 1, text: 'My text'},
{id: 2, text: 'Another Item'}
]);
var myTable = new TableView({
collection: list
});
myTable.render();