Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9191153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:37:02+00:00 2026-06-17T20:37:02+00:00

Based on the KnockoutJS mapping documentation what I am trying to do seems really

  • 0

Based on the KnockoutJS mapping documentation what I am trying to do seems really straightforward, however I am not getting the results I expect.

So for some simple test html-

<div data-bind="with: rootItem">
<p data-bind="text: subProperty"></p>
    <div data-bind="with: subObject">
        <p data-bind="text: subSubProperty"></p>
</div>

and this simple view model and application

var vm = function(){
this.rootItem = ko.observable();

this.loadData = function(data){

    //map the rootObject here
    ko.mapping.fromJS(data,{},this.rootItem());

    //this.rootItem is undefined
    console.log(this.rootItem());
 };


};
   //create new viewmodel
    var myVM = new vm();
   //create some dummy data with nested objects and properties
    var data = {
    subProperty: "Top Level Property",
    subObject: {
        subSubProperty:"Sub Level Property",
        },
    };
  //load the data
  myVM.loadData(data);
  //apply the vm
  ko.applyBindings(myVM);

So the vm.rootObject never gets set. Am I missing something about the ko.mapping plugin behavior?

This implementation of the loadData function gets the desired result, but adds the extra step.

this.loadData = function(data){

    //map the rootObject here
     this.rootItem(ko.mapping.fromJS(data));

    //this.rootItem is an object with a nested object and observable properties
    console.log(this.rootItem());
 };

Why does the first method fail? In the documentation it states pretty clearly that “The third parameter to ko.mapping.fromJS indicates the target.”

Here is a fiddle demonstrating what is happening.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:37:03+00:00Added an answer on June 17, 2026 at 8:37 pm

    The documentation is right “The third parameter to ko.mapping.fromJS indicates the target.”.
    But you provide the wrong target:

    because when you call ko.mapping.fromJS(data,{}, this.rootItem()); the this.rootItem is initialized with undefined so the mapping plugin cannot use it a target.

    Use an empty object when creating the rootItem and it will work fine:

    var vm = function(){
        this.rootItem = ko.observable({});
    
        this.loadData = function(data){     
            ko.mapping.fromJS(data,{}, this.rootItem());             
         };
    };
    

    Demo JSFiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started to play around with knockoutjs and do some simple binding/dependant binding.
I have a search form & knockout-based grid for results. When search is performed,
I am working through the mapping plugin example on the Knockoutjs website. This is
I am trying to build a Nested Editable gridview with KnockoutJS, and I have
I am trying to bind a select with KnockoutJS to a predefined value that
I'm creating a commenting system with knockout.js and I'm having some issues with getting
I have an example jsfiddle here that generates some html content based on a
I've been working on a single page app based on Knockoutjs' excellent mail example
I'm new to KnockoutJS but am liking it so far. What I'm trying to
I have a form with some fields getting some data using knockout.js (ver. 2.1.0).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.