Описание тега knockout-mapping-plugin
Knockout.js Mapping is an open source Knockout.js plugin that simplifies the mapping a plain JavaScript object or JSON string to a Knockout view model.
Knockout.js Mapping, also known as ko-mapping, is an open source knockout.js plugin that simplifies the mapping a plain JavaScript object or JSON string to a Knockout view model.
Without knockout-mapping
// declare view model and explicitly declare each observable property
var viewModel = {
id: ko.observable(),
name: ko.observable(),
projects: ko.observableArray()
};
// get a response from the server in a variable `data`
{
id: 1,
name: 'Steve Sanderson',
projects: ['knockout', 'knockout.mapping']
}
// apply server response to viewModel
viewModel.id(data.id);
viewModel.name(data.name);
viewModel.projects(data.projects);
With knockout-mapping
// declare view model
var viewModel = {};
// get a response from the server in a variable `data`
{
id: 1,
name: 'Steve Sanderson',
projects: ['knockout', 'knockout.mapping']
}
// apply server response to viewModel
// this augments observable properties onto the viewModel and is configurable
viewModel = ko.mapping.fromJS(data);
Helpful Links