Skip to content

Instantly share code, notes, and snippets.

@bionicbrian
Created December 14, 2011 22:22
Show Gist options
  • Save bionicbrian/1478840 to your computer and use it in GitHub Desktop.
Save bionicbrian/1478840 to your computer and use it in GitHub Desktop.
ListView Coffee
class ListView extends Backbone.View
el: $('#myList')
events:
'keypress #myInputForm': 'addWithReturn'
initialize: ->
@collection = window.Items
@collection.bind('add', @appendItem)
render: =>
@
addWithReturn: (e) =>
val = $('#myInputForm').val()
if e.keyCode is 13
if val is ''
window.myAlert("You have to input some text!")
else
$('#myInputForm').val('')
@item = new Item({text: val})
@collection.add(@item)
appendItem: =>
itemView = new ItemView({ model: @item })
$(@el).show()
$(@el).append(itemView.render().el)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment