Backbone.js not registering Model.hasChanged event
- by Brian M. Hunt
Hello,
I'm trying to get a View in Backbone.js to save when there's a 'change' event if (and only if) the data has changed.
Long story short, I've a 'change' event set on the View that calls this:
function changed_event() {
log.debug("Before: " + this.model.get('name')) // not 'contrived!'
this.model.set({'name': 'contrived!'});
log.debug("After: " + this.model.get('name')) // 'contrived!'
if (this.model.hasChanged()) {
alert("This is never called.");
}
}
I'd like to know why the model.hasChanged() is false when clearly the model has been changed.
I'm not sure what other information is necessary, but if there is more information that may be helpful please comment and I'll elaborate.
Thank you for reading.