Revisions
-
Gary Rennie revised this gist
Dec 8, 2011 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ $ -> @model = Song console.log "initializing SongsView" console.log @collection @collection.bind("reset", @render) @collection.fetch() render: => @@ -41,4 +41,5 @@ $ -> console.log "template: #{@template}" $('#song-list').html @template songView = new SongsView(collection: songs) songs.fetch() -
s.ross created this gist
Dec 8, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ SONG_TEMPLATE = ''' <table> {{#if songs.length }} {{#each songs}} <tr><td>{{ this.name }}</td><td>{{ this.duration }}</td></tr> {{/each}} {{/if}} </table> ''' $ -> class Song extends Backbone.Model parse: (response) -> console.log "model parsing #{response}" # class Songs extends Backbone.Collection initialize: -> @model = Song @url = "/songs/data" parse: (response) -> console.log "collection parsing" console.log response songs = new Songs class SongsView extends Backbone.View initialize: -> @model = Song console.log "initializing SongsView" console.log @collection @collection.bind("fetch", @render) @collection.fetch() render: => console.log "render" console.log @collection template = Handlebars.compile(SONG_TEMPLATE) @template = template(songs: @collection.toJSON()) console.log "template: #{@template}" $('#song-list').html @template songView = new SongsView(collection: songs)