0

I have an ember controller as follows

App.IndexController = Ember.Controller.extend({
   edwin:{
    uno:'hola',
    dos:'hola dos',
    tres:'hola tres'
  }
});

I my template I need the value of the property edwin, if I get the property as

  <script type="text/x-handlebars" data-template-name="index">
  {{edwin.dos}}
  </script>

It works fine, but I need to select the object element from other variable, when I try

 <script type="text/x-handlebars" data-template-name="index">
  {{edwin['dos']}}
  </script>

or

 <script type="text/x-handlebars" data-template-name="index">
  {{edwin[myvar]}}
  </script>

I can't display the value this is my jsbin

http://emberjs.jsbin.com/xupuse/1/edit

any suggestions

1
  • This isn't supported in handlebars. if you can provide a real use case I'd be glad to provide you with an alternative. Commented Apr 8, 2014 at 0:04

1 Answer 1

1

The closest you'll get it creating some dynamic property in the controller, based on another property. The real problem will be if the other property changes, ember won't know to update it. In the example below, if edwin.xxxx changed the computed property wouldn't know*, whereas if dynamo changed it would know (since it's watching it).

App.IndexController = Ember.Controller.extend({
  edwin:{
    uno:'hola',
    dos:'hola dos',
    tres:'hola tres'
  },
  dynamo: 'uno',
  dynamoProperty: function(){
    return this.get('edwin.' + this.get('dynamo'));
  }.property('dynamo')
});

http://emberjs.jsbin.com/beziq/1/edit

*I'm kind of lying here, you could specify each and every property on edwin and it would always be marked dirty, regardless of whether or not it applied to dynamoProperty a la

  dynamoProperty: function(){
    return this.get('edwin.' + this.get('dynamo'));
  }.property('dynamo', 'edwin.{uno,dos,tres}')

http://emberjs.jsbin.com/beziq/2/edit

Sign up to request clarification or add additional context in comments.

1 Comment

That's almost what I need to achive with this differences: 1. The controller is an ArrayController. 2. The dinamo property is not part of the controller instead is part of the model. Y need the property to apply a css based in the state of the model row.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.