Having the following model:
var dataModel = ko.observable({ someProp: ko.observable() }); var isValid = ko.pureComputed(function () { return dataModel().isValid; }); I have the following function:
function testMe() { dataModel().isValid = false; // This does not work, why? console.log("isValid: " + isValid()); // Doesn't update, shows old value dataModel({ isValid: false }); // This works however I loose all other properties console.log("isValid: " + isValid()); // Prints correctly updated value console.log(ko.toJSON(dataModel())); } Whenever I run testMe()
dataModel.isValid = false
and execute
console.log("isValid: " + isValid())
it's still set to "true" even I've set it to false above...why?. The only way I got it to work is to do
dataModel({ isValid: false }); however this way I loose all other properties in my model. How can I make this work?
What am i doing wrong?