Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your <code>parse()</code> function shouldn't <code>set()</code> anything, its a better practice to just return the attributes, Backbone will take care of setting it. e.g.</p> <pre><code>parse: function(response) { response.summaryList = new JobSummaryList(response.summaryList); return response; } </code></pre> <p>Whatever you return from <code>parse()</code> is <a href="https://github.com/documentcloud/backbone/blob/master/backbone.js#L284" rel="noreferrer">passed to <code>set()</code></a>.</p> <p>Not returning anything (which is like returning <code>undefined</code>) is the same as calling <code>set(undefined)</code>, which could cause it not to pass validation, or some other unexpected results if your custom <code>validate()</code>/<code>set()</code> methods expects to get an object. If your validation or <code>set()</code> method fails because of that, the <code>options.success</code> callback passed to <code>Backbone.Model#fetch()</code> won't be called.</p> <p>Also, to make this more generic, so that <code>set()</code>ing to a plain object from other places (and not only from the server response) also effects it, you might want to override <code>set()</code> instead:</p> <pre><code>set: function(attributes, options) { if (attributes.summaryList !== undefined &amp;&amp; !(attributes.summaryList instanceof JobSummaryList)) { attributes.summaryList = new JobSummaryList(attributes.summaryList); } return Backbone.Model.prototype.set.call(this, attributes, options); } </code></pre> <p>You might also find <a href="https://github.com/PaulUithol/Backbone-relational" rel="noreferrer">Backbone-relational</a> interesting - it makes it much easier to deal with collections/models nested inside models.</p> <p><strong>edit</strong> I forgot to return from the set() method, the code is now updated</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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