Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access outer loop property in nested 'foreach'

Tags:

I have a nested foreach loop in Knockout.js and I want to access a property from the current object in the outer loop inside the inner loop.

<!-- ko foreach: graduationDateRows -->                     <tr>     <td class="center" data-bind="text: CalendarYear"></td>       <!-- ko foreach: $root.graduationDatesHeaders -->     <td class="center" data-bind="text: /* !here! */"></td>      <td></td>     <!-- /ko -->                                                                     </tr>  <!-- /ko --> 

How would I do this?

like image 665
Adam Levitt Avatar asked Jun 12 '12 02:06

Adam Levitt


1 Answers

You can use $parent to access one scope level up. So, from your inner loop you can use parent to access the current item being looped on in your graduationDateRows

like image 76
RP Niemeyer Avatar answered Oct 14 '22 03:10

RP Niemeyer