0

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.

1
  • 1
    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. Commented Jan 24, 2013 at 16:44

2 Answers 2

1

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);

    });
}});
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.