dimanche 24 mai 2015

Ember js access different model data from template

Im using the sane stack with mongo db. I'm fairly new to emberjs. I'm using ember 0.2.5 and sails 0.11.0 and mongodb.

I have a game route, controller and model that I can properly access from the game template. I also have a separate player route, controller, model, template setup that I can also access and manipulate properly.

A game has two players, and the player has a logo. Given I have the game data which contains each player id, I basically want to do get the player logo using the player id and display that in the game template.

Ive tried a few things, this is my last attempt to put that logic in the game controller.

//model/game.js

import DS from 'ember-data';

export default DS.Model.extend({
    home_player: DS.attr('string'),
    away_player: DS.attr('string'),
    players: DS.hasMany('players'),
});



//Here's the logic of what I want to achieve

playerLogo: function(playerName){
  for (player in players) 
    if player.name == playerName
    return player.logo_url);
}

I've searched a bit I don't see an straight forward answer to this (or a solution I understand).

Thanks




Aucun commentaire:

Enregistrer un commentaire