0
votes

When i try set my 'content' to the customerList i'll get the error:

Uncaught TypeError: Object #Object has no method 'set'

Here is my code:

  App.TableController = Em.ArrayController.extend({
init: function() {
    this._super();
    this.getData();
},
getData: function() {
    $.get('data/customer.json', function(data) {
        var customerList = Ember.A([]);
        data.forEach(function(item) {
            var customer = App.overv.create({
                incidient: item.incidient,
                customer: item.customer,
                machine: item.machine,
                priority: item.priority

            });
            customerList.pushObject(customer);
        });
        this.set('content', customerList);

    });
}});

I I also tried it with App.router.tableController.set('content',customerList) but ember doesn't recognize the controller anymore. With 1.0.0 pre 2 this second example worked great. Now i try to figure out what i did wrong or probably understood wrong.

2
this specified in:this.set('content', customerList);looks to not be the controller (but probably the window). It should work if you define: var self = this at the first line of getData, and then replace this with self.louiscoquio

2 Answers

1
votes

Keep a reference of this in a local variable _self. See code below.

App.TableController = Em.ArrayController.extend({
init: function() {
    this._super();
    this.getData();
},
getData: function() {
    var _self = this;
    $.get('data/customer.json', function(data) {
        var customerList = Ember.A([]);
        data.forEach(function(item) {
            var customer = App.overv.create({
                incidient: item.incidient,
                customer: item.customer,
                machine: item.machine,
                priority: item.priority

            });
            customerList.pushObject(customer);
        });
        _self.set('content', customerList);

    });
}});
1
votes

probably just an issue with the context of the AJAX callback... you could try this:

App.TableController = Em.ArrayController.extend({
  init: function() {
      this._super();
      this.getData();
  },
  getData: function() {
      $.ajax({
        url: 'data/customer.json',
        dataType: 'json',
        context: this
      }).success(function(data, textStatus, jqXHR) { 
        var customerList = Ember.A([]);
        data.forEach(function(item) {
            var customer = App.overv.create({
                incidient: item.incidient,
                customer: item.customer,
                machine: item.machine,
                priority: item.priority

            });
            customerList.pushObject(customer);
        });
        this.set('content', customerList);
      });
  }
});

specifying TableController as the context to the callback.