SteveSanderson/knockout.mapping — Issue #58: Options for toJS generation (similar to fromJS)
Author: philipmat
Created: 2012-02-24 16:26:29+00:00
State: open

Would it be possible to have the same control over object generation when performing `toJS(viewModel)` as we have when calling `fromJS` through the `mapping` parameter?

In other words, just like we have a "create" mapping when converting to the VM:

```js
var mapping = {
'children': {
create: function(options) {
return new myChildModel(options.data);
}
}
}
ko.mapping.fromJS(data, mapping)
```

could we have a similar mapping:

```js
var mapping = {
'children': {
create: function(options) {
// i realize this is not a good example, but it's illustrative.
return { id: options.data.id, name : options.data.firstName };
}
}
}
ko.mapping.toJS(data, mapping)
```