Thursday, June 21, 2018

Working with Knockout Mapping

To work with properties of an object we have to first declare it with its property which can be observable. To work with this, we have to fetch some of the values from service and assign those manually. To overcome this situation we can use Knockout Mapping. If we assign incoming data mapping by knockout mapper it will create observable for each properties which act just like what we have created manually.

To work with knockout mapping, we have to include knockout mapper along with knockout.js 
http://cdnjs.cloudflare.com/ajax/libs/knockout.mapping/2.3.5/knockout.mapping.js

To create new variable use "var MyData = ko.mapping.fromJS(serviceData)"
In above statement, "serviceData" is data from service which will be mapped with "ko.observable" to "MyData".

Knockout Mapping


No comments:

Post a Comment