title: Updating a Knockoutjs observable array item
body: <p>How do I update an "employee" array item in the observable array "employees" when the save/edit button attached to that item is clicked? </p>
  
  <p>One possibility I'm exploring is passing the index of the current employee/item to KO's "replace" method used in the "editEmployee" function - which i've started to look at here <a href="http://jsfiddle.net/72T8h/" rel="nofollow">http://jsfiddle.net/72T8h/</a></p>
  
  <p>I also need to prevent the current item values (in edit mode) from updating in the observable array when the "cancel" button is clicked or another employee is added or deleted)</p>
  
  <pre><code>function Employee() {
  
      var self = this;
  
      this.firstName = "";
      this.lastName = "";
      this.fundName = "";
  
      //Toggle editability
      this.editable = ko.observable(true);
  
      // Employee summary of details
      this.removeEmployee = function (employee) {
          vm.removeEmployee(this);
      };
  
  //      this.cancelUpdate = function () {
  //          this.editable(!this.editable());
  //      };
  
      this.editEmployee = function (employee) {
          this.editable(!this.editable());
          vm.editEmployee(this);
      };
  
  }
  
  
  function EmployeesViewModel() {
  
      var self = this;
  
      self.employees = ko.observableArray([]);
  
      self.removeEmployee = function (employee) {
          self.employees.remove(employee);
      };
  
      self.addEmployee = function () {
          self.employees.push(new Employee());
      };
  
      self.editEmployee = function(employee){
  
          //*** REPLACE ITEM IN ARRAY HERE ***
          self.employees.replace(self.employees()[self.index()],employee);
      };
  }
  
  var vm = new EmployeesViewModel();
  ko.applyBindings(vm);
  </code></pre>