{{get}} helper with dynamic key not working


#1

In a component I have the following property:

values: {
  4: {
    'value': 5,
    'unit': 'km/h'
  },
  8: {
    'value': 7,
    'unit': 'db'
  }
},
indexes: [4, 8]

In it’s template, I need to dynamically access this property. Until I updated my app to 2.4 the following has worked:

{{#each indexes as |index delta|}}
  index: {{index}}<br />
  value: {{get (get values index) "value"}}<br />
{{/each}}

Now the result is just:

index: 4
value: 
index: 8
value: 

However, if I replace the dynamic index part with a static index, it works:

{{#each indexes as |index delta|}}
  index: {{index}}<br />
  value: {{get (get values "8") "value"}}<br />
{{/each}}


index: 4
value: 7
index: 8
value: 7

There’s no error in JS console.

DEBUG: -------------------------------
DEBUG: Ember      : 2.4.3
DEBUG: Ember Data : 2.4.1
DEBUG: jQuery     : 1.12.2
DEBUG: -------------------------------

Any idea what’s going wrong here?


#2

The issue is that the get helper only allows string keys (see here). I’m not sure exactly why that restriction was added, but this seems like a bug to me. See demo twiddle.

I created https://github.com/emberjs/ember.js/issues/13296 to track this issue.


#3

You’re right, @rwjblue. Thank you! Will have to use a custom helper until this is fixed.