When I try to update a model in Backbone via save the change event on the model is fired twice. Events are fired in this order.
- change
- request
- change
- sync
However, if I pass (wait: true), only the first change event is fired.
Can anybody explain why this is happening, and how I can get change to only fire once without passing (wait: true)?
Two change events:
editItem: function() {
this.model.save({
name: "Howard the Duck"
});
}
One change event:
editItem: function() {
this.model.save({
name: "Howard the Duck"
}, (wait: true);
}
Pseudo code:
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");
}
});