vendredi 26 juin 2015

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

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.[]'),




Aucun commentaire:

Enregistrer un commentaire