Comments (10)
Fixed problem with ko.mapping.fromJSON ignoring options. Closed by 10d0274.
from knockout.mapping.
This still doesn't work with toJS or toJSON. Basically my 'mapping' parameter (which I presume is options, since it's undocumented) gets ignored.
from knockout.mapping.
Can you add a reproduction scenario on jsfiddle?
from knockout.mapping.
Just so I'm not wasting time here: how should the mapping object (as given on the ko.mapping documentation page on the KO site) be passed to ko.toJS/ko.toJSON? I only see an options parameter for these functions, so I'm a bit confused.
from knockout.mapping.
It should simply be passed in as the only parameter, the options are automatically taken from the mapped object (inside your mapped object there is a ko_mapping property), e.g.:
var unmapped = ko.mapping.toJS(mappedViewModel);
from knockout.mapping.
Ah right... so I need to set the ko_mapping property to the 'mapping' object mentioned on the KO site. The KO site doesn't mention this at all! This just sounds like documentation needs to be updated. It's not very good atm to be fair. But thanks for the quick reply anyway.
from knockout.mapping.
No, this property is set automatically when you create a mapped object. The normal flow is something like:
var mappedViewModel = ko.mapping.fromJS(data);
// do stuff
var unmapped = ko.mapping.toJS(mappedViewModel);
mappedViewModel already contains the ko_mapping property, you don't need to do this manually. This is why it is not documented.
from knockout.mapping.
Oh, I see. And I think you mean that the mapping object can only be passed in on fromJS, per the Knockout documentation. e.g.
ko.mapping.fromJS(data, mapping)
but not the corresponding for the toJS/toJSON functions?
from knockout.mapping.
Yes, fromJS is intended to be used only with objects created with toJS. I hope this clarifies the problems you are seeing.
from knockout.mapping.
Thanks, all is clear now.
from knockout.mapping.
Related Issues (20)
- mapping fails if value = "constructor" HOT 2
- Is there a way to update the nested properties of the items of an ObservableArray? HOT 1
- Method visitPropertiesOrArrayEntries is doing unnecessary iterations on updateViewModel because the wrong variable is being used to check against ignored properties.
- Mapping not saved when data is an array HOT 1
- Mapping doesn't work when properties listed in different order HOT 4
- Empty observe array in mapping options creates observables from all properties HOT 1
- ko.mapping.toJSON to implement JSON formatting param like ko.toJSON
- Calling fromJS to amend an existing model with an ObservableArray fails
- NuGet package install directory
- Questions about Knockout Mapping HOT 10
- The "create" handler does not work with non-array properties HOT 1
- Create handler causes mapping to evaluate pureComputed HOT 1
- Suggestion: Safely update mapping when property in new object happens to be null
- mapping partial model into existing viewModel
- [Question] is arrayChanged part of the public api?
- objectLookup() + "watch" + Firefox = hilarity
- bug of optimizedKeys
- optionsCaption causes bound "value" to be deleted
- Doesn't seem to work with KO 3.4.2 HOT 1
- Having redudant data passed to an object makes it so the second reference of the same object is not updated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from knockout.mapping.