0

I have a computed observable:

passengerDocs.passengerDocsViewModel = function () {
var self = this;
self.isFunctionsDone = ko.observableArray([false, false, false, false, false, false, false]);
self.IsCompleted = ko.computed(function () {
    var isFinished = true;
    ko.utils.arrayForEach(self.isFunctionsDone(), function (x) {
        if (x == false) isFinished = false;
    });

    return isFinished;
});

problem is that it always returns false even if all the elelments of isFunctionDone are true. Any ideas?

Guy Z
  • 683
  • 3
  • 8
  • 24
  • Something else is wrong, because your code should and in fact it works: http://jsfiddle.net/ELPJr/. Can you maybe post some more context maybe a repro in JSFiddle? – nemesv Jun 26 '13 at 07:17

1 Answers1

0

ko.utils.arrayForEach not all time correctly interacts with ko.computed, it will be better if it will be replaced with simple for. Also, probably, you have issue in if statement, because it only checks last value in array.

function Model() {
    var self = this;
    self.isFunctionsDone = ko.observableArray([false, false, false, false, false, false, true]);

    self.IsCompleted = ko.computed(function () {
        for(var i = 0; i <= self.isFunctionsDone().length; i++)
             if (self.isFunctionsDone()[i] === false) 
                return false;
        return true;
    });
}
Damien
  • 8,889
  • 3
  • 32
  • 40
Maxim Nikonov
  • 674
  • 4
  • 13