Amar Amar - 1 month ago 6
Javascript Question

EmberJs : #each loop not detecting the array defined in the component

This might seem simple, but i am missing something here. Please help me out.

in the component's JS file -

weekShorts: computed(function() {
return new Array('S', 'M', 'T', 'W', 'T', 'F', 'S');
}),


and then in hbs file -

{{#each day in weekShorts}}
<td> {{day}}</td>
{{else}}
<td>
No items in days
</td>
{{/each}}


The output is always "No items in days".

Although, just printing {{weekShorts}} anywhere else, displays

S,M,T,W,T,F,S


Why is the #each loop not executing the loop over the array at all?

EDIT - This works !!!, as suggested in the comments for 2.x

{{#each weekShorts as |day|}}
<td> {{day}}</td>
{{else}}
<td>
No items in days
</td>
{{/each}}

Answer

If your ember version is greater than 1.12, use as:

{{#each weekShorts as |day|}}

To read further, look at deprecations' blog