backbone-generator/templates/collection_view.coffee.erb

21 lines
568 B
Plaintext

class window.<%= plural_object_name %>View extends Backbone.View
events: {
'click button.new': 'addNew'
}
template: JST['<%= plural_underscore_name %>/list']
initialize: ->
@collection.bind('refresh', this.addAll)
render: =>
$(this.el).html(this.template())
this
addOne: (model) =>
view = new <%= object_name %>View({model: model})
this.$('.list').append(view.render().el)
addAll: =>
@collection.each(this.addOne())
addNew: =>
facility = new <%= object_name %>()
@collection.add(facility)
this.addOne(facility)