Updating a product
In our catalog, we will want to update the value of our product. To complete this action, follow these steps:
First, to update a product you need to mock the URI that handles the action:
$.mockjax({ url: /^\/products\/([\d]+)$/, type:'PUT', dataType: 'json', responseTime: 750, status:200, responseText: { 'data': { text: 'Product saved' } } });
Add a button in each row in the
catalog.html
view, in the same cell you have theadd-to-cart-button
component:<button class='btn btn-info' data-bind='click: $parent.openEditModal'> <i class='glyphicon glyphicon-pencil'></i> </button>
Now, open a modal with the data of this product:
var openEditModal = function (product) { tmpProduct = ProductService.clone(product); selectedProduct(product); $('#editProductModal').modal('show'); };
The
tmpProduct
will contain a copy of the object you are going to edit:Var tmpProduct = null;
The
selectedProduct
will contain...