Git Product home page Git Product logo

Comments (10)

sagacity avatar sagacity commented on August 17, 2024

Fixed problem with ko.mapping.fromJSON ignoring options. Closed by 10d0274.

from knockout.mapping.

alexreg avatar alexreg commented on August 17, 2024

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.

sagacity avatar sagacity commented on August 17, 2024

Can you add a reproduction scenario on jsfiddle?

from knockout.mapping.

alexreg avatar alexreg commented on August 17, 2024

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.

sagacity avatar sagacity commented on August 17, 2024

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.

alexreg avatar alexreg commented on August 17, 2024

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.

sagacity avatar sagacity commented on August 17, 2024

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.

alexreg avatar alexreg commented on August 17, 2024

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.

sagacity avatar sagacity commented on August 17, 2024

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.

alexreg avatar alexreg commented on August 17, 2024

Thanks, all is clear now.

from knockout.mapping.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.