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:
// INSIDE PARENT MODEL
computedValue: function () {
var value = this.get('childModel').get('childModelProperty');
return value;
}
This seems to work fine for keeping my UI in sync, but as soon as I call
.save()
on the parent model, I get:
Uncaught TypeError: Object #<Object> has no method 'get'
It seems that the child model kind of temporarily stops responding.
Am I doing something inherently wrong?
EDIT: The stack trace is:
Uncaught TypeError: Object #<Object> 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
EDIT #2 in response to comment below:
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.
I'm not yet pulling anything from the server, the parent model is just created like
define(['jquery', 'underscore', 'backbone', 'models/childmodel'], function($, _, Backbone, ChildModel) {
var ParentModel = Backbone.Model.extend({
defaults: {
childModel : new ChildModel()
}