Folliwing instructions given in the documentation, I have the following view model:
var newContactViewModel = function () {
var self = this;
self.Name = ko.observable();
self.Address = ko.observable();
self.City = ko.observable();
self.State = ko.observable();
self.PostalCode = ko.observable();
self.Save = function () {
$.ajax({
type: "POST",
url: "/contact",
data: ko.toJS(self), //infinite loop here
success: state.OnSaved
});
};
};
When the self.Save
method is called, an infinite loop occurs. Chrome actually reports the error as:
Uncaught RangeError: Maximum call stack size exceeded
If I use ko.mapping.toJS(self)
instead of ko.toJS(self)
, then I get a slightly more revealing error, but no real error "message":
If I swap ko.toJS(self)
out with something like { Name: self.Name(), Address: self.Address() /* etc */ }
, then everything works fine. It seems like it's trying to convert the Save
method and re-calling the method as a result.
There's either a bug in KnockoutJS or there's a problem when how I'm using it. I'd prefer the latter. Thoughts?