Gary Zi
Gary Zi

Reputation: 95

knockoutjs not updating

I must have missed something in this example. Could anyone let me know what might be wrong?

Link: http://jsfiddle.net/EBxy4/42/

screen: shared screen

When you update the value in box 1 in row 1, the value in lower corner doesn't change.

The code is:

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"));​

Upvotes: 0

Views: 232

Answers (1)

Matt Burland
Matt Burland

Reputation: 45135

Your problem is in your binding, replace this:

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

with:

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

Here's a working fiddle:

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

I even fixed your subtotal which was concatenating rather than summing!

Upvotes: 1

Related Questions