如何将foreach实例作为方法参数传递?

时间:2015-02-12 06:47:49

标签: knockout.js

如何将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>

1 个答案:

答案 0 :(得分:2)

$ data是&#34; foreach&#34;中的当前数组条目。结合:

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

$ index也是迭代索引(可观察)。有关详细信息,请参阅foreach binding documentation