public
Created

  • Download Gist
WordListView.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
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()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.