backbone.js - Backbone View method not firing on first load -
when entries/index
loaded, should fire @collection.each(@appendentry)
appends entries in collection #entries
, nothing happens. if submit new entry, works fine.
entries_index.js.coffee
:
class raffler.views.entriesindex extends backbone.view template: jst['entries/index'] events: 'submit #new_entry': 'createentry' initialize: -> @collection.on('add', @render, this) render: -> $(@el).html(@template(collection: @collection)) @collection.each(@appendentry) appendentry: (entry) -> view = new raffler.views.entry() $('#entries').append(view.render().el) createentry: (event) -> event.preventdefault() @collection.create name: $('#new_entry_name').val()
what going on here?
try calling render
within initialize
.
@collection.each(@appendentry)
inside render function, not being called view during initialize
.
the reason can see after adding items render being called each time item added collection, via binding: @collection.on('add', @render, this)
Comments
Post a Comment