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


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


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