Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8352875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:05:52+00:00 2026-06-09T09:05:52+00:00

Getting my brain wrapped around emberjs. Trying to create a controller that loads objects

  • 0

Getting 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");
    });
  }
});

Upon calling MTM.Trade.controller.loadAll(), it’s clear that the loop is being called for each object. However my controller never changes.. running console.log MTM.Trade.controller.get('content') returns a blank array.

I know that ember-rest and ember-data exist, but for now I’m rolling-my-own to learn how to do these things myself, and the will migrate to those frameworks later.

UPDATE

Thanks to this article I did get the answer to my question.. I need to init my array as such:

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

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

loadAll: function() {
    ...

So now my question is, why? Intuitively shouldn’t the ArrayController initializer take care of this? Perhaps this is not the way an ArrayController is expected to be used?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:05:53+00:00Added an answer on June 9, 2026 at 9:05 am

    Before your update, I put a comment, where I told you to initialize the content at creation time (so in the hash of the create).

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

    But then I saw that you were setting content to [] in the loadAll function. So I was thinking that initialization was unnecessary.

    When looking closest to ArrayController, it’s just an extension of the ArrayProxy mixin, (ie: kinds of interface), so when creating an instance of an ArrayController, you must define the content property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to wrap my brain around parallel/concurrent programming (in Java) and am getting
I am trying to write a routine that takes a UIImage and returns a
I'm having problems getting my brain around this. I have four models: Account has
I am trying to wrap my brain around Rack::Cache, Rails 3.2, Memcache, and Heroku.
I'm trying to update a combobox/datagrid sorter that came from flex3 to a flex4
Brain getting foggy on this one. I wanted to take my dice game from
Getting my head around Android, I've sort of trouble understanding support for multiple devices.
Getting extremely confused with an adminhtml module i'm trying to write! Effectively I have
Getting 401 errors when trying to use ASP.NET back end in load balanced environment
Getting 'Dispatcher has no subscribers' error while trying to post message to a channel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.