Object mapping plugin for Knockout
Official documentation here.
bower install bower-knockout-mapping --savenpm install knockout-mapping --savevardata={email: 'demo@example.com',name: 'demo',addresses: [{type: 'home',country: 'Romania',city: 'Cluj'},{type: 'work',country: 'Spain',city: 'Barcelona'}]};// Create a view model from datavarviewModel=ko.mapping.fromJS(data);// Now use the viewModel to change some values (properties are now observable)viewModel.email('demo2@example.com');viewModel.name('demo2');viewModel.addresses()[0].city('Bucharest');// Retrieve the updated data (as JS object)varnewData=ko.mapping.toJS(viewModel);// newData now looks like this{email: 'demo2@example.com',name: 'demo2',addresses: [{type: 'home',country: 'Romania',city: 'Bucharest'},{type: 'work',country: 'Spain',city: 'Barcelona'}]}Run this example in JSFiddle.
Unless CI environment variable is defined, the tests use the latest version Knockout.