vendredi 26 juin 2015

Knockout computed write not firing

I have a simple grid, with checkable rows.

Each row represents basically this object:

function Person(name, isChecked, isDisabled) {
        this.name = name;
        this.isChecked = ko.observable(isChecked);
        this.isDisabled = ko.observable(isDisabled);
    };

There's also a check all checkbox in the grid header, which should check all the non-disabled rows or un-check them (depending on the state). This should also work the other way around, meaning that when I check all the rows within the grid (clickin on each row's checkbox), the header checkbox should be checked.

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

See this example: http://ift.tt/1TRb8ek.

Notice that when you check them all, the alert within the write function is executed. However, when you uncheck, it no longer works.

Consider this version where I comment the if statement (lines 30 and 32): http://ift.tt/1SPBdcg.

In this version, it seems to run well whether it's check or uncheck, but at the cost of not taking into account the disabled rows.

I'm pretty sure there's a minor thing I'm missing there..




Aucun commentaire:

Enregistrer un commentaire