Created
December 14, 2011 22:22
-
-
Save bionicbrian/1478840 to your computer and use it in GitHub Desktop.
ListView Coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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