Skip to content

@sxross /backbone_render.coffee
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Backbone render
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"
window.songs = new Songs
class SongsView extends Backbone.View
initialize: ->
@el = 'body'
@model = Song
@collection.bind("reset", @render)
@collection.fetch()
@events = {'click button': 'zeep'}
@delegateEvents()
@render()
render: (arg) =>
console.log "render"
console.log @collection
template = Handlebars.compile(SONG_TEMPLATE)
@template = template(songs: @collection.toJSON())
console.log "template: #{@template}"
$('#song-list').html @template
zeep: =>
console.log 'zeep!'
@collection.fetch()
window.songView = new SongsView(collection: window.songs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.