0

在这个例子中我一定遗漏了一些东西。谁能让我知道可能出了什么问题?

链接:http: //jsfiddle.net/EBxy4/42/

屏幕:共享屏幕

当您更新第 1 行中框 1 中的值时,下角的值不会改变。

代码是:

function revenueStream(w1, w2, w3) {
    var self = this;
    self.week1Amount = ko.observable(w1);
    self.week2Amount = ko.observable(w2);
    self.week3Amount = ko.observable(w3);
}

function revenueStreamCategory(revenueStreams) {
    var self = this;
    self.revenueStreams = ko.observalrevenueStreams;

    self.week1Sum = ko.computed(function () {
        var sum = 0.0;

        ko.utils.arrayForEach(self.revenueStreams, function(item) {
            sum += item.week1Amount();
        });      
        return sum;
    });    
}

var rs = [];
rs.push(new revenueStream(10, 11, 12));
rs.push(new revenueStream(13, 14, 15));    
rs.push(new revenueStream(16, 17, 18));

var vm = new revenueStreamCategory(rs);      

ko.applyBindings(vm, document.getElementById("test"));​
4

1 回答 1

1

你的问题出在你的绑定上,替换这个:

<td><input data-bind="value: week1Amount()" /></td>

和:

<td><input data-bind="value: week1Amount" /></td>

这是一个工作小提琴:

http://jsfiddle.net/EBxy4/44/

我什至修复了你的小计,它是连接而不是求和!

于 2012-12-20T21:27:12.570 回答