Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Values for Key in Handlebars & Ember

Is it possible to access properties in a value-for-key style in Handlebars?

I have a CollectionView which uses an ArrayController full of models. The CollectionView has a property called 'columns' that define table column configurations for rendering.

Ideally I'd be able to loop through each column (see example below) ensuring that only the columns we want rendered are rendered (and later, formatting and other attributes are applied)

<tr>
  {{#each column in view.controller.columns}}
    <td>
      {{ view.content.[column.name] }}
    </td>
  {{/each}}
</tr>

This doesn't work, it just returns no content.

I've also tried these other styles to see if they'd work:

<tr>
  {{#each column in view.controller.columns}}
    <td>
      {{ view.content.name }}
      {{ view.content.[column.name] }}
      {{valForKey view.content column.name }}
    </td>
  {{/each}}
</tr>

The valForKey helper is one I wrote (source here), which does display the correct value but doesn't bind, so the value isn't updated when the property changes.

What's the best way to handle this use case in Ember?

Thanks

like image 792
d2kagw Avatar asked Nov 13 '22 02:11

d2kagw


1 Answers

Right now Ember has get helper included:

{{get object key}}
like image 51
Karol Szambelańczyk Avatar answered Dec 06 '22 12:12

Karol Szambelańczyk