Ember.js PushObject no inserta un objeto en un ArrayController

I have the following ArrayController:

Lead.Controllers.Leads = Ember.ArrayController.extend
  init: ->
    content: Ember.A()

    @view = Ember.View.create
      controller: @
      templateName: 'app/templates/leads/list'

    @view.appendTo $('#leads')

  addLead: (data) ->
    lead = Lead.Lead.create()
    lead.setProperties JSON.parse data
    console.log lead.get 'company'
    @pushObject lead
    console.log @get('length')

The problem is after I call push object, the length is still 0. I really cannot see what I am doing wrong.

Can anyone see what I am doing wrong? The only thing I can think of is that the Content is set to an empty array via Ember.A().

I have no idea what else it could be.

preguntado el 09 de marzo de 12 a las 15:03

2 Respuestas

I'm not quite sure where your problem is since I a) don't really know or use CoffeeScript and b) there's no jsFiddle or working example. But if I'm reading this correctly your trying to do the following: Ver este jsFiddle which works as expected. Hope that points you in the right direction.

respondido 09 mar '12, 19:03

Thanks, I was not calling _super() from init. That was the bit I was missing. It is a pity that is needed. - dagda1

Se trata de un Guión de café error de sintaxis.
There are two solutions (depending on what you want to implement).

The second example will use the same array for every instance of the controller.
Also, I'd recommend calling @_super() when overriding the init method, otherwise you might get some unexpected results with certain classes.

  init: ->
    @set 'content', Ember.A()
    # content

  content: Ember.A()
  init: ->
    # content

respondido 11 mar '12, 19:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.