When I use ko.mapping.toJSON
it converts any changes I made into strings and they need to be numbers. I tried using the custom mapping like so:
var mapping = {
'y': {
update: function(options) {
return parseFloat(options.data);
}
}
}
... but this only keeps them as numbers inside the contect of the page. Since I am using this to update and external JSON that gets pulled in by HighCharts.js the numbers need to stay numbers even after the toJSON.
From an earlier answer here I was able to use:
//override toJSON to turn it back into a single val
mappedData.prototype.toJSON = function() {
return parseInt(ko.utils.unwrapObservable(this.val), 10); //parseInt if you want or not
};
... which worked swimmingly. However this is just a single value type in the JSON so I am unclear on how I could use the same override for it. Do I need to create a whole new object to do this in this instance as well. Or is their something more concise?