Backbone when the options data are not ready and the view is loaded

Backbone when the options data are not ready and the view is loaded

1
2
3
4
5
6
7
class MyWorkSpace.Views.MyView extends MyWorkSpace.Views.Base
  myMethodName: ->
      @partnerModel = new MyWorkSpace.Models.PartnerModel id: @options.id
 
      invoicesView = new MyWorkSpace.Views.InvoicesView
                                             el: @$('#invoices')
                                             partner: @partnerModel

The key is remember add in the initialize method an event on change data

1
2
3
4
5
6
7
8
9
class MyWorkSpace.Views.InvoicesView extends MyWorkSpace.Views.Base
 
  #In our view we need to do the next:
  initialize: ->
     @options.partner.on 'change', @ourMethod, @
 
  #and now the data is available jeje
  ourMethod: ->
     console.log @options.partner.get('attribute')
No Comments

Post A Comment