I have a Marionette.ItemView that uses a CSS class to style new items differently:
class Happenator.Views.Option extends Backbone.Marionette.ItemView
tagName: 'li'
className: =>
return 'new' if @model.isNew()
initialize: ->
@bindTo @model, "change", -> @render()
When the model is saved and updated, everything refreshes but the ‘new’ class remains on the ‘li’. Is there a good way to update the enclosing tags’ class on updates?
Yes, the ‘new’ class remains on the ‘li’, because in fact Backbone uses the
classNameproperty only right before an initialize method call. Take a look at this answer for more explanations.But why don’t use jQuery
.toggleClassor.removeClass? Something likehttp://jsfiddle.net/GX8WJ/21/