Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping Plugin Example #1986

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions documentation/plugins-mapping.md 100644 → 100755
Expand Up @@ -213,14 +213,20 @@ The `ignore` array you specify in the mapping options is combined with the defau
When converting your view model back to a JS object, by default the mapping plugin will only include properties that were part of your original view model, except it will also include the Knockout-generated `_destroy` property even if it was not part of your original object. However, you can choose to customize this array:

var mapping = {
'include': ["propertyToInclude", "alsoIncludeThis"]
'myProperty': ["propertyToInclude", "alsoIncludeThis"]
}
var viewModel = ko.mapping.fromJS(data, mapping);

The `include` array you specify in the mapping options is combined with the default `include` array, which by default only contains `_destroy`. You can manipulate this default array like this:
By default, the `myProperty` array you specify in the mapping options is not included. To include it, you can manipulate the `ko.mapping.defaultOptions().include` array, which by default only contains `_destroy`. Add `myProperty` as follows:

var oldOptions = ko.mapping.defaultOptions().include;
ko.mapping.defaultOptions().include = ["alwaysIncludeThis"];
var mappingOptions = ko.mapping.defaultOptions();
mappingOptions.include.push('checked');
ko.mapping.defaultOptions(mappingOptions);

or

var defaultOptions = ko.mapping.defaultOptions().include;
ko.mapping.defaultOptions().include = ["myProperty"];

###### Copying certain properties using "copy"

Expand Down