-
-
Save Gazler/1449022 to your computer and use it in GitHub Desktop.
Backbone render
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 characters
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("reset", @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) | |
songs.fetch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment