javascript - Knockout computed write not firing -


i have simple grid, checkable rows.

each row represents object:

function person(name, ischecked, isdisabled) {         this.name = name;         this.ischecked = ko.observable(ischecked);         this.isdisabled = ko.observable(isdisabled);     }; 

there's check all checkbox in grid header, should check non-disabled rows or un-check them (depending on state). should work other way around, meaning when check rows within grid (clickin on each row's checkbox), header checkbox should checked.

the problem is, computed bound check all checkbox fails execute.

see example: http://jsfiddle.net/eww5dn8q/.

notice when check them all, alert within write function executed. however, when uncheck, no longer works.

consider version comment if statement (lines 30 , 32): http://jsfiddle.net/qws3f7js/.

in version, seems run whether it's check or uncheck, @ cost of not taking account disabled rows.

i'm pretty sure there's minor thing i'm missing there..

cf. comment on question: 'error' indeed minor. modifying computed's read function did trick (plus simplifies if else clause if):

  read: function () {       var isallselected = true;       $.each(self.mydata(), function(i, person){           if(!person.ischecked() && !person.isdisabled()){               isallselected = false;           }       });       return isallselected;   }, 

see fiddle: http://jsfiddle.net/kevinvanlierde/eww5dn8q/1/


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -