title: How Do I Call A Function In A ViewModel Knockout
body: <p>I have a model called customer:</p>
  
  <pre><code>function customer(id, name, age, comments) {
      var self = this;
  
      self.Id = id;
      self.Name = name;
      self.Age = age,
          self.Comments = comments;
  
      self.addCustomer = function () {
          $.ajax({
              url: "/api/customer/",
              type: 'post',
              data: ko.toJSON(this),
              contentType: 'application/json',
              success: function (result) {
                  //SOMETHINGS WRONG HERE
                  customerVM();
              }
          });
      }
  }
  </code></pre>
  
  <p>After I add a customer the list of customers doesnt automatically update. Calling customerVM() in the model goes into the viewModel function but never goes into the getCustomers function, so I must be calling the viewModel wrong. Thats what I am seeing from debugging. </p>
  
  <p>The function that displays the list is in the viewModel:</p>
  
  <pre><code>function customerVM() {
      var self = this;
      self.customers = ko.observableArray([]);
      self.getCustomers = function () {
          self.customers.removeAll();
          $.getJSON("/api/customer/", function (data) {
              $.each(data, function (key, val) {
                  self.customers.push(new customer(val.Id, val.Name, val.Age, val.Comments));
              });
          });
      };
  }
  </code></pre>
  
  <p>I need to call getCustomers somehow after adding a customer. How might I do this??</p>
  
  <p>Here is the customers html</p>
  
  <pre><code>&lt;table &gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Id&lt;/th&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Age&lt;/th&gt;
              &lt;th&gt;Comments&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody data-bind="foreach: customers" &gt;
          &lt;tr&gt;
              &lt;td data-bind="text: Id"&gt;&lt;/td&gt;
              &lt;td data-bind="text: Name"&gt;&lt;/td&gt;
              &lt;td data-bind="text: Age"&gt;&lt;/td&gt;
              &lt;td data-bind="text: Comments"&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;br /&gt;
  &lt;input type="button" id="btnGetCustomers" value="Get Customers" data-bind="click: getCustomers" /&gt;
  </code></pre>