Backbone.js not registering Model.hasChanged event

Posted by Brian M. Hunt on Stack Overflow See other posts from Stack Overflow or by Brian M. Hunt
Published on 2011-02-21T23:23:04Z Indexed on 2011/02/21 23:25 UTC
Read the original article Hit count: 435

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about backbone.js