title: Access index of $parent in knockout.js
body: <p>In knockout.js 2.1.0, in a template using the foreach binding, you can access the current item's index though the $index() function. In a nested foreach binding, is there any way to access the index of the $parent from a template?</p>
  
  <p>Say I have a data structure like this:</p>
  
  <pre><code>var application = {
    topModel: [
      {
        {subModel: [{'foo':'foo'}, { 'bar':'bar'}]}, // this has top:0 and sub:0
        {subModel: [{'foo2':'foo2'}, { 'bar2':'bar2'}]} // this has top:0 and sub:1
      },
      {
        {subModel: [{'foo':'foo'}, { 'bar':'bar'}]} // this is top:1 sub:0
      },
      {
        {subModel: [{'foo':'foo'}, { 'bar':'bar'}]} // this is top:2 sub:0
        {subModel: [{'foo':'foo'}, { 'bar':'bar'}]} // this is top:2 sub:1
      },
      ...
      ]};
  </code></pre>
  
  <p>With this, I want to print the path to each model, using indices:
  [topModel-index subModel-index], so that the output will be something like:</p>
  
  <pre><code>[0 0]
  [0 1]
  [1 0]
  [2 0]
  [2 1]
  ...
  </code></pre>
  
  <p>I have bound the models using foreach, but I can't figure out how to access the topModel's index in the context of the subModel. The following example shows an approach I have tried, but it doesn't work, as I can't figure out how to access the index of the $parent referrer.</p>
  
  <pre><code>&lt;!--ko foreach: topModel --&gt;
  &lt;!--ko foreach: subModel --&gt;
    [&lt;span data-bind="text: $parent.index()"&gt;&lt;/span&gt;
    &lt;span data-bind="text: $index()"&gt;&lt;/span&gt;]
  &lt;!--/ko--&gt;
  &lt;!--/ko--&gt;
  </code></pre>
  
  <p>Should print out: 0 1, 0 2, 1 0, 1 1, 1 2, 2 0, 2 1, ...</p>