title: Nested loops in knockout.js
body: <p>I'm starting learn some web programming and picked up knockout.js because the MVVM pattern is familiar to me having some experience with MVVM in .Net.</p>
  
  <p>But I'm having some trouble making loops with nested arrays. The model is very simple: I have an array of topics each having an array of stories.</p>
  
  <p>You can check the full code on <a href="http://jsfiddle.net/QCY4r/" rel="nofollow">Fiddle</a>, but here is a simplified version:</p>
  
  <p>ViewModel.js:</p>
  
  <pre><code>function Story(t, u, v) {
      var self = this;
  
      self.summary = ko.observable(t);
      self.url = ko.observable(u);
      self.up_votes = ko.observable(v);
  }
  
  function Topic(t) {
      var self = this;
  
      self.title = ko.observable(t);
      self.stories = ko.observableArray();
  }
  
  function TopicListViewModel() {
      var self = this;
      self.topics = ko.observableArray([]);
  }
  </code></pre>
  
  <p>topic.html:</p>
  
  <pre><code>&lt;!-- ko foreach: topics --&gt;
  &lt;div class="span2"&gt;
      &lt;table cellpadding="2" cellspacing="2" style="width:100%" class="table"&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                      &lt;span data-bind="text: title"&gt; &lt;/span&gt;
                  &lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
  
          &lt;tbody data-bind="foreach: $data.stories"&gt;
              &lt;tr&gt;
                  &lt;!--&lt;a data-bind="attrib: { href: url, title: summary} "&gt;&lt;/a&gt;--&gt;
                  &lt;span data-bind="text: summary"&gt; &lt;/span&gt;
              &lt;/tr&gt;
          &lt;/tbody&gt;
  
      &lt;/table&gt;
  &lt;/div&gt;
  &lt;!-- /ko --&gt;​
  </code></pre>
  
  <p>The problem I keep getting is in the stories loop. I keep getting <code>Message: ReferenceError: summary is not defined;</code> but I debugged the code in Chrome and stories is indeed an array of objects with property <code>summary</code> defined.</p>
  
  <p>What am I doing wrong here?</p>