Ember.js pushObject not pushing

How my brain wrapped around emberjs. Trying to create a controller that loads objects from a webservice call that returns a JSON array:

(Note that this is javascript generated from coffeescript)

MTM.Trade.controller = Ember.ArrayController.create({
  loadAll: function() {
    var self;
    self = this;
    this.set('content', []); /* fails with or without this line*/
    return $.getJSON('http://localhost:8080/webservice/trades', function(data) {
      var jsonTrade, trade, _i, _len;
      console.log("Length = " + data.length);
      for (_i = 0, _len = data.length; _i < _len; _i++) {
        jsonTrade = data[_i];
        trade = MTM.Trade.create(jsonTrade);
        self.pushObject(trade);
      }
      console.log("Everything pushed");
    });
  }
});

When called, MTM.Trade.controller.loadAll()it is clear that the loop is called for each object. However, my controller never changes. console.log MTM.Trade.controller.get('content')returns an empty array.

I know that there are data with ember-rest and ember-data, but for now I will refuse to find out how to do it myself, and the will will be transferred to this framework later.

UPDATE

Thanks in this article I got the answer to my question .. I need to initialize the array as such:

MTM.Trade.controller = Ember.ArrayController.create({

  init: function() {
    this._super();
    return this.set('content', Ember.A());
  },

loadAll: function() {
    ...

, : ? ArrayController ? , ArrayController?

+5
1

, ( ).

MTM.Trade.controller = Ember.ArrayController.create({
    content: [],
    //...
});

, content [] loadAll. , .

ArrayController ArrayProxy mixin (.. ), ArrayController content.

+1

All Articles