Created
June 14, 2012 19:20
-
-
Save billyvg/2932337 to your computer and use it in GitHub Desktop.
Backbone.js ListView + RowView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ListView extends Backbone.View | |
constructor: (options) -> | |
super | |
@view = options.view if options.view? | |
@collection.on 'add', @addRow, @ | |
@collection.on 'remove', @removeRow, @ | |
@collection.on 'reset', @render, @ | |
@ | |
### | |
# Called when a model is added to the collection. | |
# Renders a new row in the table view. | |
### | |
addRow: (model) -> | |
view = new @view | |
model: model | |
@$el.append(view.render().el) | |
view.delegateEvents() | |
model.view = view | |
@ | |
### | |
# Called when a model is removed from the collection. | |
# Removes the item from the table view. | |
### | |
removeRow: (model) -> | |
model.clear() | |
@ | |
# Clears the table view of Assets and re-renders it. | |
render: -> | |
@$el.html('') | |
@collection.map (model) => | |
@addRow model |
It's actually not needed, left it in there by mistake (old code).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what's the point in calling delegateEvents on the child view? (just trying to understand it's usage)