我很难过这个。我有一个简单的骨干关系模型:骨干关系改变事件没有发射?
window.Site = Backbone.RelationalModel.extend({
idAttribute: "_id",
// These are the relations to the user model.
relations: [{
type: Backbone.HasMany,
key: 'users',
relatedModel: 'window.User'
}],
});
我的用户模型(这是关系到网站的模式)是这样的:
//Site User model
// -------------
window.User = Backbone.RelationalModel.extend({
});
用户模型有意保持愚蠢的,因为我还在原型。
我从服务器接收到滋润网站和用户的JSON看起来是这样的:
{
_id: foo,
users: [
username: bar,
password: fizz
]}
我很为难的是听众。这是对的SiteView(这使得我SiteCollection)事件是这样的:
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);
的add:users
和remove:users
事件触发罚款,但change:users
事件不会。在DetailsView,这使得我的用户模型,我也有一些简单的事件绑定:
initialize: function() {
this.model.bind('change', this.render, this);
this.model.bind('destroy', this.remove, this);
但是,出于某种原因,该change:users
事件中的SiteView不火,而change
事件在DetailsView一样。
难道这是因为:
- 的
change
事件上的用户模型两种不同的观点,势必两次? - 用户模式不是双向的吗?
此外,结合更新':users'给出了相同的结果 – CamelBlues 2012-08-15 18:53:26