Note that there are some explanatory texts on larger screens.

plurals
  1. POKnockoutjs mapping - without initial data
    primarykey
    data
    text
    <p>Using knockoutjs, i'm attempting to map a large and complex piece of data. I'm using the revealing module pattern. </p> <p>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 <em>not</em> 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.</p> <p>This is the only info anywhere that is sort of related</p> <p><a href="https://stackoverflow.com/questions/6735225/knockout-js-mapping-plugin-without-initial-data-empty-form">Knockout JS mapping plugin without initial data / empty form</a></p> <p>but this doesn't really solve the same problem - or at least, I can't make it solve the same problem. </p> <p>And here's roughly the code i've got. </p> <pre><code>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(); }); }); </code></pre> <p>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.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload