I am unable to get the knockout.js mapping options to work on nested values. With the following code, the first level "shouldBeCopied" works fine and the nested "shouldBeCopied" value is always an observable.
var data = {
shouldBeCopied: "copied",
nested: {
shouldBeCopied : "copied"
}
};
var vm = ko.mapping.fromJS(data, {
'copy': ["shouldBeCopied"],
"nested": {
'copy': ["shouldBeCopied"]
}
});
console.log(vm);
Any ideas?
Here's a fiddle if anyone wants to play around with it.
When using the the
copy
,ignore
,observe
, etc options you don't need to minic the object structure in your mapping options (like when usingcreate
)What you need to to is to use a property accessor expression (
"nested.shouldBeCopied"
) in yourcopy
array to configure nested properties:Will output:
Demo JSFiddle.