ECAILLE Fabrice (externe) e2277667c5 Fix: add dependencies 8 anos atrás
..
dist e2277667c5 Fix: add dependencies 8 anos atrás
.bower.json e2277667c5 Fix: add dependencies 8 anos atrás
HISTORY.md e2277667c5 Fix: add dependencies 8 anos atrás
LICENSE e2277667c5 Fix: add dependencies 8 anos atrás
README.md e2277667c5 Fix: add dependencies 8 anos atrás
bower.json e2277667c5 Fix: add dependencies 8 anos atrás
package.json e2277667c5 Fix: add dependencies 8 anos atrás

README.md

knockout.mapping

Build Status

Object mapping plugin for Knockout

Documentation

Official documentation here.

Install

Bower

bower install bower-knockout-mapping --save-dev

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

Continuous Integration tests are done with Travis, and the associated Gulp task is test-ci. For development test task is used, which runs the tests against the latest version of Knockout.

License

MIT