Package Exports
- ko-mapping
- ko-mapping/dist/knockout.mapping.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ko-mapping) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
knockout.mapping
Object mapping plugin for Knockout with built-in types, forked from https://github.com/crissdev/knockout.mapping
Documentation
Official documentation here.
Install
NPM
npm install ko-mapping --save
Quick Start
var data = {
email: 'demo@example.com',
name: 'demo',
addresses: [
{ type: 'home', country: 'Romania', city: 'Cluj' },
{ type: 'work', country: 'Spain', city: 'Barcelona' }
]
};
// Create a view model from data
var viewModel = 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)
var newData = 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.
Test
Unless CI
environment variable is defined, the tests use the latest version Knockout.