im trying to set an element with a class of either 'inactive' or 'active' depending on the models isActive
property.
<tr class="inactive">
And heres what I have. 'inactive' is default. the resulting render is that all tr elements have class of 'inactive'
var ItemView = Backbone.View.extend({
tagName: "tr",
className: 'inactive',
render : function() {
this.className = this.model.get('Active') ? 'active' : 'inactive';
...
this.$el.html( this.template(data) );
}
});
Found some small print
className: function() {
var el = this.model.get('Active') ? 'active' : 'inactive'; // Set active flag in class
return el;
},
However, now get error: 'this.model' is undefined
suggesting that className function is run prior to initialize. im using default initializer. and this.model
in render
never had a problem.