title: Knockout.js dynamic binding of observables
body: <p>I am trying to utilize knockout to create an editable table.  I have a JSON object that has a collection of both headings and table data.  This table needs to be built using any object.  It will loop over the JSON object to create ko.observableArray and the ko.observables to populate it.  I have been able to do that.  My problem is that the ko.observables are not being data bound.  </p>
  
  <p>Here is a snippet of my JavaScript:</p>
  
  <pre><code>EditableTableVM.prototype.load = function() {
      this.headings = this.buildKO_ObservableArray(new Heading(), this.dataRepo.HEADINGS);
      this.listings = this.buildKO_ObservableArray(new Listing(), this.dataRepo.LISTINGS);
  }
  
  /*
   * Dynamically creates a ko.observableArray from a JS array
   * Params: JSClass - new instance of a class
   * Params: baseArray - array of objects to create the observable array
   * Returns: Observable arary of JS object with ko.observables
   */
  EditableTableVM.prototype.buildKO_ObservableArray = function(JSClass, baseArray) {
      var newArray = ko.observableArray([]);
  
      for(var i = 0, j = baseArray.length; i &lt; j; i++) {
          var baseObj = baseArray[i];
  
          //new class is the class with ko.observables properties
          var newClass = this.buildKO_Observable(JSClass, baseObj);
          newArray.push(newClass);
      }
  
      return newArray;
  }
  
  /*
   * Dynamically create ko.observable from properties in an object
   * Params: JSClass - new instance of a class
   * Params: jsObject - object to created observables with
   * Returns: JS object with ko.observables
   */
  EditableTableVM.prototype.buildKO_Observable = function(JSClass, jsObj) {
      for (var key in jsObj) {
          if (jsObj.hasOwnProperty(key)) {
              JSClass[key] = ko.observable(jsObj[key]);
          }
      }
  
      return JSClass;
  }
  </code></pre>
  
  <p>Here is my Fiddle <a href="http://jsfiddle.net/breck421/YFNLX/" rel="nofollow">http://jsfiddle.net/breck421/YFNLX/</a> with it working up to the point I described earlier.</p>
  
  <p>I am not sure if what I am trying to do is possible or not and would really appreciate another set of eyes on this.</p>
  
  <p>Thanks,</p>
  
  <p>Jordan</p>