Note that there are some explanatory texts on larger screens.

plurals
  1. PONo method 'get' on backbone model save
    primarykey
    data
    text
    <p>I'm using backbone for a reasonably complicated form. I have a number of nested models, and have been computing other variables in the parent model like so:</p> <pre><code>// INSIDE PARENT MODEL computedValue: function () { var value = this.get('childModel').get('childModelProperty'); return value; } </code></pre> <p>This seems to work fine for keeping my UI in sync, but as soon as I call</p> <pre><code>.save() </code></pre> <p>on the parent model, I get:</p> <pre><code>Uncaught TypeError: Object #&lt;Object&gt; has no method 'get' </code></pre> <p>It seems that the child model kind of temporarily stops responding.</p> <p>Am I doing something inherently wrong?</p> <p>EDIT: The stack trace is:</p> <pre><code>Uncaught TypeError: Object #&lt;Object&gt; has no method 'get' publish.js:90 Backbone.Model.extend.neutralDivisionComputer publish.js:90 Backbone.Model.extend.setNeutralComputed publish.js:39 Backbone.Events.trigger backbone.js:163 _.extend.change backbone.js:473 _.extend.set backbone.js:314 _.extend.save.options.success backbone.js:385 f.Callbacks.o jquery.min.js:2 f.Callbacks.p.fireWith jquery.min.js:2 w jquery.min.js:4 f.support.ajax.f.ajaxTransport.send.d </code></pre> <p>EDIT #2 in response to comment below:</p> <p>There's something basic I'm still not getting. I replaced a few references to this.get('childModel')['childModelProperty'] and now I get things like 'cannot read property childModelProperty of undefined.</p> <p>I'm not yet pulling anything from the server, the parent model is just created like</p> <pre><code>define(['jquery', 'underscore', 'backbone', 'models/childmodel'], function($, _, Backbone, ChildModel) { var ParentModel = Backbone.Model.extend({ defaults: { childModel : new ChildModel() } </code></pre>
    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