ObjectAt(0) doesn't work with Ember.Controller


#1

I’m trying to upgrade my Ember application to the latest Ember 1.13.2 and therefore am trying to replace all Ember.ArrayController with Ember.Controller.

I’ve got a problem with the category-controller of my blog. The data retrieved from my server looks like this:

 "posts": [
    {
      "category": {
         "id": "1",
         "name": "tech"}
      "title": "my title",
      "body": "post-content",
      "isPublished": true,
    },
   ...
   ]

In my category-controller I need both, the category-id and the category-name.

With the Ember.ArrayController I used objectAt(0) to get both from the first post loaded in the model for that purpose but this doesn’t work with Ember.Controller anymore.

How can I get these two attributes in my controller?

This code doesn’t work anymore:

  breadCrumb: function(){
    return this.objectAt(0).get('category').get('name');
  }.property('model.[]'),

  categoryId: function(){
    return this.objectAt(0).get('category').get('id');
  }.property('model.[]'),

#2

Need more details.

All array-like methods are not part of Ember.Controller, since it’s not an array-like shape.

I assume this posts array is stored somewhere on your model, or is your model. It’s hard to tell in the details you’ve given. But going off that assumption, your objectAt should be something like this.get('model.firstObject.category.name'); or this.get('model.posts.firstObject.category.name');