You can create a view for the whole row. For each row you would need a row-model with item
and price
attributes which you would pass into the row-view's constructor. This pretty much looks like the TableView
in your code (except I would expect that to be called RowView
instead, the TableView
being a different, 'parent' view)
Given that your model contains item
and price
attributes, the row-view-template should contain
....
<td><%=item%></td>
<td><%=price%></td>
....
Then this.model.toJSON()
would give you a hash with item
and price
attributes which would be passed into this.template
, populating <%=item%>
and <%=price%>
with the relevant values.
You can also take a look at underscore's template function for further information.
Note however that the row-view and the table-view should be two different views. From your code it seems that you have a template appropriate for a table-view (which also contains a single row that shouldn't be there) and a view appropriate as a row-view.
Having two views you would pass a collection of row-models in the table-view which would iterate over the collection and add a row(-view) for each model. When the user creates a new item you'd add a model into the collection and re-render the table.
Hope this helps.