knockout.js嵌套的foreach访问外部循环属性 [英] knockout.js nested foreach access outer loop property

查看:259
本文介绍了knockout.js嵌套的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. How would I do this?

<!-- 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

这篇关于knockout.js嵌套的foreach访问外部循环属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆