【发布时间】:2013-05-17 01:23:34
【问题描述】:
我对 Knockout 非常(非常!)新手,希望您能就以下问题为我指明正确的方向。
我有一个我在 jsFiddle 上寻找的最终结果示例
最终,我希望在绑定到价格(将动态加载)的表格行中有多个复选框。行中的最后一个单元格将保存所有已选择价格的平均值(复选框已选中)。
这是我对 ViewModel 的了解:
//--Page ViewModel
//--Set the structure for the basic price object
function Price(quote) {
this.quote = ko.observable(quote);
}
//--Sets the structure for the contract month object
//--This includes the month, and array of Price and an average
function ContractMonthPrices(month, prices) {
this.month = month;
this.prices = $.map(prices, function(quote) { return new Price(quote); });
this.average = ko.computed(function() {
var total = 0;
for(var i = 0; i < this.prices.length; i++)
total += this.prices[i].quote();
return total;
}, this);
}
我知道这可能没用,但我们将不胜感激!
谢谢!
【问题讨论】:
-
好的,但是你的问题是什么?什么不工作?
-
暂时没有!我无法理解如何绑定复选框,因为我读过的所有内容都显示了一个复选框“列表”而不是表格。
标签: javascript html knockout.js