I'm stumped on this. I have a simple backbone-relational model:
window.Site = Backbone.RelationalModel.extend({
idAttribute: "_id",
// These are the relations to the user model.
relations: [{
type: Backbone.HasMany,
key: 'users',
relatedModel: 'window.User'
}],
});
And my user model (which is related to the site model) looks like this:
//Site User model
// -------------
window.User = Backbone.RelationalModel.extend({
});
The user model is intentionally kept dumb, as I'm still prototyping.
The JSON I receive from the server to hydrate the Site and users looks something like this:
{
_id: foo,
users: [
username: bar,
password: fizz
]}
What I'm stumped on is the listeners. The events that are on the SiteView (which renders my SiteCollection) look like this:
initialize: function() {
//basic bindings
this.model.bind('change', this.setSave, this);
this.model.bind('destroy', this.remove, this);
// bindings to sub-models
this.model.bind('add:users', this.setDetailsView, this);
this.model.bind('remove:users', this.setSave, this);
this.model.bind('change:users', this.setSave, this);
The add:users
and remove:users
events fire fine, but the change:users
event does not. In the DetailsView, which renders my Users models, I also have some simple event bindings:
initialize: function() {
this.model.bind('change', this.render, this);
this.model.bind('destroy', this.remove, this);
But, for some reason, the change:users
event in the SiteView does not fire, while the change
event in the DetailsView does.
Could this be because:
- The
change
event on the Users models is bound twice in two different views? - The Users model is not bidirectional?