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);
});
当我使用 mappingSetting 将 repo 映射到 viewModel 时,我发现 viewModel.status:"this has been updated"