例如我有这样的模板,我想根据当前 $index 动态计算一些值
<div class="cond" title="Click to flip">
<div class="condFlip" data-bind="attr: {id: Id }, click: viewModel.setClick">
<div class="piece-all piece" data-bind="attr: {style: background-position: viewModel.getValue($index) viewModel.getValue($index) }"></div>
</div>
</div>
</script>
<script type="text/javascript">
viewModel = {
flips: ko.observableArray([]),
setClick: function (data, e) {
e.preventDefault();
//doing things
},
getValue: function (data, e) {
return //get my value
}
};
ko.applyBindings(viewModel);
那么如何在模型绑定中使用函数 viewModel.getValue 呢?有什么办法吗?