jeudi 29 octobre 2015

Ember js display each item in javascript array in {{#each}} helper

I am creating the following array variable in an ember component, and passing it to the controller for my template file.

var errors = [
0: "Line 2 needs a tab separator."
1: "Line 42 is empty."
2: "Line 43 is empty."
3: "Line 44 is empty."
4: "Line 45 is empty."
5: "Line 46 is empty."
6: "Line 47 is empty."];

In the controller I am setting a property to this array value:

this.set('errorList', errors);

I can then display the array in the template file:

{{controller.errorList}}

The problem is that the errors display as one long string like so:

Line 2 needs a tab separator.,Line 42 is empty.,Line 43 is empty.,Line 44 is empty.,Line 45 is empty.,Line 46 is empty.,Line 47 is empty.

Is it possible to use an {{#each}} helper to display each item, and thus become able to to add in HTML tags- eg:

<ul>
{{#each **** as |***|}
 <li>***Display each individual error here.***</li>
{{/each}}
</ul>

Would it help if I was able to convert the array variable into a JSON object?




Aucun commentaire:

Enregistrer un commentaire