Updating a product

In our catalog, we will want to update the value of our product. To complete this action, follow these steps:

  1. 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'
            }
        }
    });
  2. Add a button in each row in the catalog.html view, in the same cell you have the add-to-cart-button component:
    <button class='btn btn-info' data-bind='click: $parent.openEditModal'>
      <i class='glyphicon glyphicon-pencil'></i>
    </button>
  3. Now, open a modal with the data of this product:
    var openEditModal = function (product) { tmpProduct = ProductService.clone(product); selectedProduct(product); ...

Get KnockoutJS Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.