title: KnockoutJS Bindings With Nested Templates
body: <p>I'm having a problem with nested bindings with Knockout.JS</p>
  
  <p>For example if I have the following in say an app.js file:</p>
  
  <pre><code>var UserModel = function() {
      this.writeups = ko.observableArray([]);
  }
  
  var WriteupModel = function() {
      this.type = 'some type';
  }
  
  var MyViewModel = function() {
      this.newUser = new UserModel();
      this.selectedUser = ko.observable(this.newUser);
  
      this.selectedUser().writeups().push(new WriteupModel());
  }
  
  ko.applyBindings(new MyViewModel());
  </code></pre>
  
  <p>and the following for a view:</p>
  
  <pre><code>&lt;div id="empReportView" data-bind="template: { name: 'empTmpl', data: selectedUser }"&gt;&lt;/div&gt;
  
  &lt;script type="text/html" id="empTmpl"&gt;
      &lt;table&gt;
          &lt;tbody data-bind="template: { name: 'empWuItem', foreach: $data.writeups } "&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/script&gt;
  
  &lt;script type="text/html" id="empWuItem"&gt;
      &lt;tr&gt;
          &lt;td data-bind="text: type"&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>Whenever another WriteupModel is pushed onto the writeups array belonging to the selectedUser the table doesn't update. This is a simplified version of what I'm trying to accomplish but it's to be assumed that when they create a writeup it should update the write-ups table based on the new information.</p>
  
  <p>I'm new to Knockout so any help would be appreciated!</p>
  
  <p>Thanks. </p>
  
  <p>-=-= Edit 1 =-=-</p>
  
  <p>One thing to note, if you reload the binding for the selectedUser it will spit out the empWuItem template for the added writeup. This just seems inefficient as the bindings should trigger when the WriteUp is added to the writeups observable array in the UserModel without have to "re-assign" the selectedUser property in the view model.</p>