I’m porting an old app to use backbone.js (hopefully)
Problem is none of the various objects in the system use ‘id’ for id –
each object is different. Reading around, I’ve come up with the solution below when initializing the Backbone.Model.
initialize: function(){
this.idAttribute = 'user_ID';
this.set({'id':this.get('user_ID')});
}
I’m worried however that as I develop with backbone this approach is gonna bite me.
Does anyone have any experience with this.
Any pointers much appreciated.
edit: I just called isNew() on the model and got true, even though the id is now set to 1.
///////////////////////////////////////////
Using the following seems to sort it out.
User = Backbone.Model.extend({
idAttribute : 'user_ID'
})
When you use idAttribute, backbone basically keeps the
idproperty in sync with theuser_IDproperty. The way it’s normally used is when you define your classGood Luck