As with most basic questions, there is no βrightβ answer to this question - you will need to find the approach that is best for you, which partly depends on how complex your application can be.
The main thing that seems strange to me in your setup is that you hardcoded your table to list the two elements - I assume that if you use Backbone to start, you will probably list the elements from the server via AJAX, and then populate the table with this list. In this case, you usually create a DOM for each row of the ItemView class:
var ItemView = Backbone.View.extend({ // there are many different ways to do this, here one tagName: 'tr', className: 'item-row', // make an Underscore template for the inner HTML template: _.template( '<td class="price"><%= price %></td>' + '<td><input type="text" class="quantity" value="<%= quantity %>" /></td>' ), render: function(){ // this.el is already set to a tr.item-row DOM element $(this.el).html( // fill in the template with model attributes this.template(this.model.toJSON()) ); // allows chaining return this; } // ... now your events and handler as written });
This gives you an ItemView that, when rendered, has the rendered item that you want to insert after calling .render() . Depending on your setup, you can immediately call this.render() in the initialize() function, or you can get additional data asynchronously, and then call render() in the callback. In any case, you have one instance of the view attached to one model. To manage multiple models, I can have another view class that will contain a collection that will be responsible for instances of child instances of ItemView :
var ItemsView = Backbone.View.extend({ el: '#myTable', render: function() { var tableView = this;
Then, in the main part of your code, all you need to do is pass the collection to the parent view and make it:
var tableView = new ItemsView({ collection: totals });
There is a lot to add, most of them are connected with asynchronous extraction, rendering and updating of data from the server, but, hopefully, this gives you a basic idea of ββthe approach. Again, however, I must emphasize that this is just one way to do something - you could, for example, build the same application with only the ItemsView class, which would make it responsible for rendering all the elements. But the approach of using a single view to manage the collection and child views to manage the models perfectly separates things and helps minimize complexity as your application grows.