当我尝试通过模型上save
的更改事件更新 Backbone 中的模型时,会触发两次。事件按此顺序触发。
- 改变
- 要求
- 改变
- 同步
但是,如果我通过,则只会触发(wait: true)
第一个事件。change
任何人都可以解释为什么会发生这种情况,以及我如何才能change
在不通过的情况下只开火一次(wait: true)
?
两个变化事件:
editItem: function() {
this.model.save({
name: "Howard the Duck"
});
}
一个变化事件:
editItem: function() {
this.model.save({
name: "Howard the Duck"
}, (wait: true);
}
伪代码:
App.Views.Item = Backbone.View.extend({
initialize: function() {
this.model.on("change", this.changing, this);
this.model.on("request", this.requesting, this);
this.model.on("sync", this.syncing, this);
},
events: {
"click a": "editItem"
},
editItem: function() {
this.model.save({
name: "Howard the Duck"
});
}
changing: function() {
console.log("changing");
},
requesting: function() {
console.log("requesting");
},
syncing: function() {
console.log("syncing");
}
});