Answer the question
In order to leave comments, you need to log in
How to set the default parameter of the second level?
There is a model.
App.Models.Dialog = Backbone.Model.extend({
defaults:{
'author': {
avatar: '/img/myAvatar.png'
},
'opponent': {
avatar: '/img/myAvatar.png'
}
}
});
author: {
id: 1,
name: "[email protected]"
},
initialize: function() {
var tmp = _.clone(this.get('author'));
if(!tmp.avatar){
tmp.avatar = '/img/myAvatar.png';
this.set('author', tmp);
}
tmp = _.clone(this.get('opponent'));
if(!tmp.avatar){
tmp.avatar = '/img/myAvatar.png';
this.set('opponent', tmp);
}
}
Answer the question
In order to leave comments, you need to log in
https://github.com/powmedia/backbone-deep-model might help. There, when assigning, deep extend is used.
Use the model's parse() method to intercept and adapt data coming from the server.
Read more in the official documentation: Model-parse
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question