2015-02-12 58 views
0

如何通過foreach實例作爲方法參數?如何通過foreach實例作爲方法參數?

在下面的代碼中,我如何將每個實例currentFeature傳遞給$root.enableDemote(currentFeature)。將它作爲$root.enableDemote(currentFeature)傳遞不起作用。任何sugegstions?

<tbody data-bind="foreach: { data: features, as: 'currentFeature' }"> 
    <tr> 
     <td style="width: 8px;"> 
      <button type="button" id="exposureDetailDemoteButton" class="btn btn-default fe-margin" data-bind="click: $root.demoteExposure, enable: $root.enableDemote(currentFeature)" data-toggle="tooltip" title="Demote Feature Exposure"><span class="glyphicon glyphicon-backward"></span></button> 
     </td> 
    </tr> 
</tbody> 

回答

2

$數據是 「的foreach」 結合內部的當前陣列條目:

data-bind="click: $root.demoteExposure, enable: $root.enableDemote($data)" 

另外$指數是迭代指數(觀察到的)。欲瞭解更多詳情,請登錄foreach binding documentation

+0

完美。 st.fwd – 2015-02-12 07:23:19

+1

非常感謝你:) – TSV 2015-02-12 07:33:46

相關問題