ToJSON View Model Overrides Not Being Reflected After Knockout Unmapping
I have a deep object graph from the server which I am representing with a Knockout view model structure which omits various unnecessary properties at each level but preserves the b
Solution 1:
A couple of things are going on here:
- your
toJSONfunction is getting called, but not as part of theko.mapping.toJSONcall. The mapping plugin does a stringify as part of determining a key for objects. ko.mapping.toJSONcreates a plan copy of the object and at that point it is no longer an instance ofParentViewModel. Then, when it stringifies the object, it will have no reason to run yourtoJSONfunction.
The call to ko.mapping.toJSON does support a second argument for options. You could pass { ignore: ['child'] } in as this argument like: http://jsfiddle.net/rniemeyer/4kHC2/

Post a Comment for "ToJSON View Model Overrides Not Being Reflected After Knockout Unmapping"