knockout.js - Knockout computed bool value not updating -
here's simple viewmodel:
var vm = { isvalid1: ko.observable(false), isvalid2: ko.observable(false), isvalid3: ko.observable(false), isvalid4: ko.observable(false), isallvalid: ko.computed(function() { return isvalid1() && isvalid2() && isvalid3() && isvalid4(); }); }
when updating isvalid , setting them true this:
vm.isvalid1(true); vm.isvalid2(true); vm.isvalid3(true); vm.isvalid4(true);
isallvalid never seems updated. doing wrong here?
thanks
nicolas
you cant use literal that, have create constructor , initiate like
var vm = function() { this.isvalid1 = ko.observable(false); this.isvalid2 = ko.observable(false); this.isvalid3 = ko.observable(false); this.isvalid4 = ko.observable(false); this.isallvalid = ko.computed(function() { return this.isvalid1() && this.isvalid2() && this.isvalid3() && this.isvalid4(); }, this); };
or set isallvalid function after creation of literal, not think literals should used vms