我有这个模板
<!--ko template: { name: 'multiCheckBtn', data: { elems: posGenders, compareWith: gender, switch: switchCheckBtn} }-->
<!--/ko-->
<script id="multiCheckBtn" type="text/html">
  <span class="fakeCheck" data-bind="foreach: { data: $data.elems, as: 't' } ">
    // here $data becomes alias to t and I don't how to access other params, like $data.switch
    <span class="btn" data-bind="text: t, css: { selected: t == $data.compareWith() }, click: $data.switch } "></span>
  </span>
</script>
我想要的是在里面foreach访问compareWith和switch传递给模板的变量,但我只能在之前访问它们foreach。内部循环$data变量成为别名t,我无法访问其他变量。
有没有办法可以将数据传递给foreach循环,以便我可以像尝试访问一样访问它?