backbone-generator/templates/collection_view.coffee.erb

22 lines
578 B
Plaintext
Raw Permalink Normal View History

2011-05-09 02:44:21 +00:00
class window.<%= plural_object_name %>View extends Backbone.View
events: {
'click button.new': 'addNew'
}
template: JST['<%= plural_underscore_name %>/list']
initialize: ->
2011-05-13 14:04:42 +00:00
@collection.bind('refresh', this.addAll)
2011-05-09 02:44:21 +00:00
render: =>
2011-05-09 11:35:37 +00:00
$(this.el).html(this.template())
2011-05-13 14:22:13 +00:00
this.addAll()
2011-05-09 02:44:21 +00:00
this
addOne: (model) =>
view = new <%= object_name %>View({model: model})
this.$('.list').append(view.render().el)
addAll: =>
2011-05-13 14:22:13 +00:00
@collection.each(this.addOne)
2011-05-09 02:44:21 +00:00
addNew: =>
2011-05-20 02:31:27 +00:00
object = new <%= object_name %>()
@collection.add(object)
this.addOne(object)
2011-05-09 02:44:21 +00:00