In this recipe, we are going to learn how to bind a collection to a view. This can be very helpful if we have different views working with the same collection, or if we want to synchronize data with a REST server.
Let's take an example of the Rendering a model in a view recipe from Chapter 4, Views, where we rendered a collection with subviews and modified it. We are going to add an additional view with the Add and Remove buttons, which will update the collection.
Also, we will bind appropriate callbacks to the model and collection events in our first view, so it is re-rendered automatically when the collection is changed.
When a user clicks on the Add button, he/she is prompted to enter the required information to create InvoiceItemModel
.
After the user goes through all the questions, a new model is created and added into a collection, and the corresponding views are updated.
When the Remove button is clicked, the user is promoted to enter the position of the item...