title: Mapping deeply hierarchical objects to custom classes using knockout mapping plugin
body: <p>Using the knockout mapping plugin ( <a href="http://knockoutjs.com/documentation/plugins-mapping.html" rel="noreferrer">http://knockoutjs.com/documentation/plugins-mapping.html</a> ) can you map a deeply hierachical object?</p>
  
  <p>If I have an object with multiple levels:</p>
  
  <pre><code>var data = {
      name: 'Graham',
      children: [
          {
              name: 'Son of Graham',
              children: [
                  {
                      name: 'Son of Son of Graham',
                      children: [
                          {
                              ... and on and on....
                          }
                      ]
  
                  }
              ]
          }
      ]
  }
  </code></pre>
  
  <p>How do I map it to my custom classes in javascript:</p>
  
  <pre><code>var mapping = {
      !! your genius solution goes here !!
  
      !! need to create a myCustomPerson object for Graham which has a child myCustomerPerson object 
      !! containing "Son of Graham" and that child object contains a child myCustomerPerson 
      !! object containing "Son of Son of Graham" and on and on....
  
  }
  
  var grahamModel = ko.mapping.fromJS(data, mapping);
  
  function myCustomPerson(name, children)
  {
       this.Name = ko.observable(name);
       this.Children = ko.observableArray(children);
  }
  </code></pre>
  
  <p><strong>Can the mapping plugin recursively map this data into an hierachy of my custom objects?</strong></p>