Marko
Marko

Reputation: 10992

Is ko.mapping.fromJS method depreceated in knockout 2.2 and 3?

I'm having a problem to use ko.mapping.fromJS( in knockout. I've been testing on version 2.2 and 3. Anybody else who has had problems? Or are there any other alternatives to updating a instatieted viewmodel?

if (PAGE.blogViewModel == null) {
                    PAGE.blogViewModel = new BlogViewModel(data);
                    ko.applyBindings(PAGE.blogViewModel, document.getElementById("blog_container"));
                } else {
                    ko.fromJSON(data, PAGE.blogViewModel); 
                }

The updating ko.fromJSON(data, PAGE.blogViewModel); does not work.

*TypeError: ko.fromJSON is not a function*

And oddly enough I've used ko.mapping.fromJS( before and it has worked.

ko.mapping.fromJS(data, PAGE.blogViewModel);

TypeError: ko.mapping is undefined

Upvotes: 0

Views: 172

Answers (2)

Karl-Johan Sjögren
Karl-Johan Sjögren

Reputation: 17577

It sounds like you haven't included the ko.mappings-library. Make sure that it is loaded after Knockout is loaded.

Upvotes: 1

nemesv
nemesv

Reputation: 139758

ko.mapping.fromJS is not deprecated because it was never part of the core Knockout library.

The ko.mapping.fromJS is comming from the Knockout Mapping plugin.

You need to download and include it separately in your HTML to use it.

Upvotes: 2

Related Questions