FutuToad
FutuToad

Reputation: 2850

How do I access an Ember.js model item without using a forEach

Usually I have to do this to access items:

setupController: function (controller, model) {
      this._super(controller, model);      
      model.accounts.forEach(function (account) {
            data.push(account.get("item"));

          });
}

Instead I just want to access the 1st item like this but it returns undefined:

  model.accounts[0]

Edit__

accounts come like so in the route:

 model: function () {

      return Ember.RSVP.hash({
        main: this.store.createRecord('main', {}),
        accounts: this.store.find('account')
      });
    },

Upvotes: 0

Views: 132

Answers (1)

imahungry
imahungry

Reputation: 126

You can create an array proxy. Then you'll have a property called firstObject and a lot of other methods built in from ember.

myArray.get('firstObject')

Here's an example: http://emberjs.com/api/classes/Ember.ArrayProxy.html

Upvotes: 2

Related Questions