Just look at previousAttributes()
Then you can compare:
If(this.get(attr) > this.previousAttributes()[attr]){ console.log('bigger'); } else { console.log('smaller'); }
If you use this in your change event handler, you are all set up. No need for a custom trigger or a ton of code.
EDIT
This is from my Backbone.Validators project and how I get a list of all the attributes that changed during the validation step:
var get_changed_attributes = function(previous, current){ var changedAttributes = []; _(current).each(function(val, key){ if(!_(previous).has(key)){ changedAttributes.push(key); } else if (!_.isEqual(val, previous[key])){ changedAttributes.push(key); } }); return changedAttributes; };
This requires Underscore 1.3.1 because it uses _.has . If you cannot upgrade, that is easy to replace. In your case, you will pass this.previousAttributes() and this.attributes
tkone
source share