O'Reilly logo

Getting Started with Knockout.js for .NET Developers by Andrey Akinshin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Introducing Knockout mapping

In this section, we will talk about the knockout.mapping plugin. This plugin allows you to map some plain JavaScript object to a Knockout.js ViewModel with observable properties. It can be very useful when you want to receive some data from the server in the JSON format and show it to the user via declarative bindings.

A manual mapping example

For better understanding of the mapping concept, let's consider an example with manual mapping of JSON data to a ViewModel object. We will take a very abridged version of the library model from the previous chapters. Suppose the model contains only two properties: LibraryName and AmountOfBooks.

  1. Let's define a corresponding ViewModel:
    var libraryViewModel = { LibraryName: ko.observable(), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required