0
votes

I currently have the following models setup using Ember Data and the Local storage adaptor.

App.Game = DS.Model.extend
 stage: DS.attr('number')
 level: DS.attr('number')
 actions: DS.hasMany('App.Action')

App.Action = DS.Model.extend
 type: DS.attr('string')
 time: DS.attr('number')
 game: DS.belongsTo('App.Game')

I can access each action from within the template using

{{#each actions}}
 {{type}}
{{/each}}

But I would like to access this same data from within the controller.

Is there are any to do this?

The following returns the actions length but I'd like to forEach over each action.

actionsLength: (->
 @get('actions').get('length')
).property('actions.@each')

The route for this controller like the following.

App.GameRoute = Ember.Route.extend
 model: (params) ->
  App.Game.find(params.game_id)

Any help would be appreciated.

1

1 Answers

0
votes

Depending from which controller you want access to the actions, have you tried to access your controller's content, for example:

App.ActionsController = Ember.ArrayController.extend({
  myFunction: function() {
    this.get('content').forEach(function(action) {
      console.log(action.get('type'));
    });
  }
});

Or from your GamesController:

App.GamesController = Ember.ArrayController.extend({
  myFunction: function() {
    this.get('content').forEach(function(game) {
      game.get('actions').forEach(function(action) {
        console.log(action.get('type'));
      });
    });
  }
});

(sorry for not coffescriptifying the code)

Hope it helps.