script.coffee | |
|---|---|
Binding DOM Events to View Methods | |
| So, part one was pretty boring. Let's spice it up by binding DOM events to our view's methods. The implementation of this step is slighlty more exciting than the last. | |
jQuery ->
class ListView extends Backbone.View
el: $ 'body'
initialize: ->
_.bindAll @
@counter = 0
@render()
| |
| We'll add a button and an empty list to our view. | render: ->
$(@el).append '<button>Add List Item</button>'
$(@el).append '<ul></ul>'
|
|
| addItem: ->
@counter++
$('ul').append "<li>Hello, Backbone #{@counter}!</li>"
|
|
| events: 'click button': 'addItem'
list_view = new ListView |
| Onward to Part 3. | |