var repo = {
desc: 'this is repo desc.',
title: 'this is title.',
job: { jobId: 1, description: 'job desc', status: 'Done', workAllowed: 'Yes' },
fault: { faultId: 1, jobId: 1, faultDescription: 'some thing', removed: 1, },
};
var mappingSettings = {
'job': {
create: function (options) {
options.data.status = "this has been created.";
return options.data;
},
update: function(options) {
options.data.status = "this has been updated";
return options.data;
}
}
};
$(document).ready(function () {
viewModel = ko.mapping.fromJS(repo, mappingSettings);
ko.applyBindings(viewModel);
});
When i map the repo to viewModel using mappingSetting, i found viewModel.status:"this has been updated"
Create is the first time when you create the model, update triggers if you map again.
http://jsfiddle.net/pHQ9t/
viewModel = ko.mapping.fromJS(repo, mappingSettings);
//Update again
ko.mapping.fromJS(repo, mappingSettings, viewModel);
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