I have an object like below.
var order = function (data) {
this.OrderId = data.Id;
this.CustomerName = ko.observable(data.CustomerName);
this.CustomerAddress = ko.observable(data.CustomerAddress);
this.CustomerPhone = ko.observable(data.CustomerPhone);
this.TotalPrice = ko.observable(data.TotalPrice);
this.Cancelled = ko.observable(data.Cancelled);
this.Pizzas = ko.observableArray();
};
In my VM:
var currentOrder = new model.Order({});
When this object gets modified from the UI, everything works fine. My problem comes in when I want to pass this object to my data layer to get saved. It comes in like:
Obviously, I can't pass this to my data layer. Is there an easy way to strip this complex object of all the knockout stuff without manually writing a big mapper?
Try this:
ko.toJS(currentOrder);
or
ko.toJSON(currentOrder);
Knockout docs here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With