I have an app which shows boxes within boxes. Each box model has a method ‘children’ which returns any boxes that are shown within the box. What I want to do is click a button and have the children rendered as a table with their properties listed in several columns.
I’m not really sure how to do this. I think the Underscore template might look something like this:
<table class='list-items-template'>
<tr>
<td><%= this.model.ITSCHILDX.get('image') %> </td>
<td><%= this.model.ITSCHILDX.get('title') %> </td>
<td><%= this.model.ITSCHILDX.get('description') %> </td>
</tr>
</table>
But then within the Box view, I need some way of saying that each child should be inserted within the table and each of its attributes should be represented. Help is greatly appreciated.
Not sure if I’m understanding the setup correctly but you have a BoxModel.
And a BoxModel can contain children BoxModels?
And you want to iterate through the children collection and represent each model as a table row?
If this is what you want here is what I’d do. A box model is represented by a BoxView which is a table and its children are essentially represented as rows. So we define it as this:
Also note, that this basically means your children boxModels are represented visually in this example. If each child (row) had to have some functionality, instead of just using the template to write out a visual representation, I’d use the
addAllRows()method to instantiate a second type of BoxModel View. A view that is a table row and has more functionality like events delegated properly.