I have a view attached to a model with an attribute “title”. I want to be able to trim the value each time it is set (for some obscure reason, I don’t want to do this on server-side). In my model I tried this:
this.on('change:title', this.trimName);
//... later on
trimName: function(){
console.log('triggered');
this.set({'title':$.trim(this.get('title'))}, {silent:true});
}
but this triggers an infinite recursion.
(Also, the recursion doesn’t happen on jsfiddle, why?).
Thanks in advance.
Make the model do the trimming: Override the
setmethod and runBackbone.Model‘ssetmethod after you trim.