我很難過這個。我有一個簡單的骨幹關係模型:骨幹關係改變事件沒有發射?
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