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

  • SEARCH
  • Home
  • 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 8821949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:58:43+00:00 2026-06-14T05:58:43+00:00

Using knockoutjs, i’m attempting to map a large and complex piece of data. I’m

  • 0

Using knockoutjs, i’m attempting to map a large and complex piece of data. I’m using the revealing module pattern.

In order to make all elements of the object observable, i’m using the mapping plugin. However, i’ve hit an issue: I cannot find, anywhere, an example of using ko.mapping.fromJS() where some initial data is not mapped on the viewmodel object, but is mapped later, after – in my case – an ajax call has been made and some data retrieved. That is, I do not have any initial data, so need the initial mapping to be full of nulls, empties, or defaults.

This is the only info anywhere that is sort of related

Knockout JS mapping plugin without initial data / empty form

but this doesn’t really solve the same problem – or at least, I can’t make it solve the same problem.

And here’s roughly the code i’ve got.

var viewModel = function(){
    var farmyard = *** What?? ***;

    var refreshData = function(){
        var temp = null;
        $.ajax(
            // awesome server call etc
            success: function(data){
                temp = data;
            }
        );
        ko.mapping.fromJS(temp, farmyard);
    };

    return{
            farmyard: farmyard,
            refreshData: refreshData
        }
};

$(function(){
   var vm = new viewModel();
   ko.applybindings(vm);

   $('#something).on('click',function(){
       vm.refreshData();
   });
});

So, my question is, what is the farmyard on the initial load of this object? At the moment I have had to setup empty objects to make this work, handcoding every element of every object, and as mentioned, the object hierarchy being mapped is large and complex, so this is not ideal. Any help much appreciated.

Thanks.

  • 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-14T05:58:44+00:00Added an answer on June 14, 2026 at 5:58 am

    I’ve resolved this by sending an empty data model into the view (this is .NET MVC) as part of the ViewBag property, and using a library called Ngon (https://github.com/brooklynDev/NGon).

    public ViewREsult Index()
    {
        var massiveDataModel = new MassiveDataModel();
    
        ViewBag.NGon.Stuff = massiveDataModel;
    
        return View();
    }
    

    And in the script:

    var viewModel = function(){
    var farmyard = ko.mapping.fromJS(ngon.Stuff);
    
    var refreshData = function(){
        var temp = null;
        $.ajax(
            // awesome server call etc
            success: function(data){
                temp = data;
            }
        );
        ko.mapping.fromJS(temp, farmyard);
    };
    
    return{
            farmyard: farmyard,
            refreshData: refreshData
        }
    };
    
        $(function(){
           var vm = new viewModel();
           ko.applybindings(vm);
    
           $('#something).on('click',function(){
               vm.refreshData();
           });
        });
    

    Was so caught up with trying to solve the problem in a certain way, couldn’t see the obvious solution. Thanks to Tyrsius for the different perspective.

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

Sidebar

Related Questions

I'm binding data to a page using KnockoutJS, the ViewModel is being populated by
We are submitting an asp.net mvc view form using the knockoutjs postJson util. All
I'm using KnockoutJS version 2.0.0 If I'm looping through all properties of an object,
I'm using KnockoutJS to iterate over an object, like this: Now this all works.
I have a page using KnockoutJS, with a somewhat large count of observables (about
I have a bound list using knockoutjs / mvc3 <div data-bind=foreach: phones> <input data-bind='value:
I want to templatize the creation of a YUI3 datatable using KnockoutJS data bindings.
I am using knockoutjs with the jquery drag & drop and it works well
I'm using KnockoutJS with ASP.NET MVC, and I'm having a problem with broken bindings
I am using KnockoutJS and I would like to know of a way where

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.