22 lines
578 B
Plaintext
22 lines
578 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.addAll()
|
|
this
|
|
addOne: (model) =>
|
|
view = new <%= object_name %>View({model: model})
|
|
this.$('.list').append(view.render().el)
|
|
addAll: =>
|
|
@collection.each(this.addOne)
|
|
addNew: =>
|
|
object = new <%= object_name %>()
|
|
@collection.add(object)
|
|
this.addOne(object)
|
|
|