访问嵌套的"foreach"中的外循环属性 [英] Access outer loop property in nested 'foreach'
本文介绍了访问嵌套的"foreach"中的外循环属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Knockout.js中有一个嵌套的foreach循环,我想从内部循环内的外部循环中的当前对象访问属性.
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 -->
我该怎么做?
推荐答案
您可以使用$parent
向上访问一个作用域级别.因此,从内部循环中,您可以使用parent
来访问在graduationDateRows
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
这篇关于访问嵌套的"foreach"中的外循环属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文