Created
April 2, 2011 19:59
-
-
Save bradphelan/899825 to your computer and use it in GitHub Desktop.
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 WordView extends Backbone.View | |
tagName: "li" | |
render: -> | |
$(this.el).html "#{@model.get('article')} #{@model.get('word')} (#{@model.get('score')})" | |
$(this.el).addClass(@model.get('article')) | |
return this | |
class WordListView extends Backbone.View | |
list: null | |
constructor: -> | |
super | |
@list = $(@el).find("ul") | |
@bindModel() | |
bindModel: -> | |
@model.bind 'add', (noun)=> @prependWord(noun) | |
@model.bind 'refresh', => @render() | |
refresh: -> | |
@list.listview("refresh") | |
prependWord: (word)-> | |
wv = new WordView({model: word}).render().el | |
@list.prepend( wv ) | |
@refresh() | |
appendWord: (word)-> | |
wv = new WordView({model: word}).render().el | |
@list.append( wv ) | |
@refresh() | |
render: -> | |
@list.html("") | |
@model.each (word) => @appendWord(word) | |
@refresh() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment