title: Accessing parent loop id using $parentContext.$index in knockout.js
body: <pre><code>&lt;div id="tree"  data-role="collapsible-set"  data-bind="foreach:VM1.Folders"&gt; **Parent Loop**
        &lt;!--Top level Folder--&gt;
        &lt;div data-role="collapsible" class="Folder" data-bind="attr:{'id':$index()}"&gt;   
          &lt;h3&gt;&lt;span data-bind="text:name"&gt;&lt;/span&gt;&lt;/h3&gt;
  
              &lt;!--Sub Folder start--&gt;
               &lt;div data-bind="attr:{'id':'subtree'+$index()} "&gt;   
             &lt;!-- ko stopBinding: true --&gt;                  
                &lt;div data-bind="foreach:VM2.SubFolders" data-role="collapsible-set"&gt;
                     &lt;div data-role="collapsible" class="SubFolder"
                     data-bind="attr{'id':$parentContext.$index}"&gt; **This gives undefined**                               
                              &lt;h3&gt;&lt;span data-bind="text:name"&gt;&lt;/span&gt;&lt;/h3&gt;
                     &lt;/div&gt;
                 &lt;/div&gt;   
             &lt;!--/ko--&gt;                
               &lt;/div&gt;
             &lt;!--End Of Sub Folder--&gt;
        &lt;/div&gt;
      &lt;!--End Of Top level Folder--&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>I am using knockout foreach binding to create jquery mobile collapsible items dynamically
  facing problem when accessing parent loops <code>$index()</code>.
  I tried both <code>$parentContext.$index()</code> and <code>$parentContext.$index</code>. Both are giving 'undefined'. I am using stop binding, is it because of that it is not able to get parent loop index?
  Following is my code.</p>