Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Changes required to trackChange and getChangesFromModel methods to support change tracking as well as detection
ko.extenders.trackChange = function (target, track) {
if (track) {
// ...
// ...
if (!target.getChanges) {
target.getChanges = function (newObject) {
var obj = target();
if ((typeof obj == "object") && (obj !== null)) {
if (target.hasValueChanged()) {
return ko.mapping.toJS(obj);
}
return getChangesFromModel(obj);
}
return target();
};
}
}
return target;
};
var getChangesFromModel = function (obj) {
var changes = null;
var properties = getObjProperties(obj);
ko.utils.arrayForEach(properties, function (property) {
if (property.value != null && typeof property.value.isDirty != "undefined" && property.value.isDirty()) {
changes = changes || {};
changes[property.name] = property.value.getChanges();
}
});
return changes;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.