@avica/knockout-mapping

2.7.0 • Public • Published

knockout.mapping

Build Status npm version

Object mapping plugin for Knockout

Documentation

Official documentation here.

Install

Bower

bower install bower-knockout-mapping --save

NPM

npm install knockout-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.

License

MIT

Dependencies (0)

    Dev Dependencies (13)

    Package Sidebar

    Install

    npm i @avica/knockout-mapping

    Weekly Downloads

    6

    Version

    2.7.0

    License

    MIT

    Unpacked Size

    107 kB

    Total Files

    7

    Last publish

    Collaborators

    • lujcon