我有以下视图模型
var viewModel = new myViewModel([{
Name: "Name",
price: 32,
tax: 22,
}, {
Name: "Name",
price: 32,
tax: 22,
}]);
我有一个数据绑定到
<tbody data-bind='foreach: personInfo'>
并输入:
<td>
<input class='required' data-bind='value: Name'/>
</td>
<td>
<input class='required' data-bind='value: Price'/>
</td>
<td>
<input class='required' data-bind='value: Tax'/>
</td>
我想获得价格的计算值,然后是税收,但是我没有成功。:(
self.totalSurcharge = ko.computed(function () {
var total = 0;
for (var i = 0; self.PersonInfo().length; i++)
total += self.PersonInfo[i].price;
return total;
});
任何想法?
更新:
像这样的东西:http: //jsfiddle.net/hamsaya/9XNDH/1/
谢谢