Skip to content

Instantly share code, notes, and snippets.

@bradphelan
Created April 2, 2011 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradphelan/899825 to your computer and use it in GitHub Desktop.
Save bradphelan/899825 to your computer and use it in GitHub Desktop.
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