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); }; 

http://jsfiddle.net/fuuqf/

or set isallvalid function after creation of literal, not think literals should used vms


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -