You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm probably doing something wrong, but in case I'm not, could there be an option to specify what attribute name the "model" is.
Currently this is model which can cause problems if the model itself has a field labelled model
varCar=Backbone.Model.extend({attributes : {'year' : 2000,'model' : '','make' : ''}});varCarViewModel=kb.ViewModel.extend({constructor : function(model){kb.ViewModel.prototype.constructor.call(this,model);// this.model() refers to the model, instead of model.get('model').}});varvm=newCarViewModel(newCar({year : 2012,model : 'Caravan',make : 'Dodge'}));
It is a little complicated to change the name of the model accessor and would make inconsistencies across view models.
Instead, you can use the internals property:
var Car = Backbone.Model.extend({});
var CarViewModel = kb.ViewModel.extend({
constructor : function(model) {
kb.ViewModel.prototype.constructor.call(this, model, {internals: ['model']});
// this.model() refers to the model, instead of model.get('model').
}
});
var model = new Car({ year : 2012, model : 'Caravan', make : 'Dodge'});
var vm = new CarViewModel(model);
vm._model() == 'Caravan'; // true
vm.model() == model; // true
I'm probably doing something wrong, but in case I'm not, could there be an option to specify what attribute name the "model" is.
Currently this is
model
which can cause problems if the model itself has a field labelledmodel
Here's a fiddle demonstrating this: http://jsfiddle.net/tbajy/
A possible fix for this would be to have an option that allows one to specify what attribute under the ViewModel the model should be.
The text was updated successfully, but these errors were encountered: