0

I have a structure like this:

 obj: {
  array: [{
   string: 'hello'
  },
   string: 'tim'
  }]
}

how can i print all the string propery in an unordered list?

i'm trying with this but it doesn't print nothing

<ul>
{{#each array}}
<li>{{this string}}</li>
{{/each}}    
</ul>
Matteo Villa
  • 47
  • 2
  • 12
  • 1
    Have a look on this answer: http://stackoverflow.com/questions/22696886/how-to-iterate-over-array-of-objects-in-handlebars. There is a working example: http://jsfiddle.net/yR7TZ/1/ as well. Looks very similar. – xszaboj Mar 06 '17 at 14:58

2 Answers2

1

TL;DR: According to each helper code in the docs, context is set to current item.

Second argument implicitly passed to helper is options object, that contains fn property. This property is a function that behaves like a normal compiled Handlebars template (containing what have been placed between {{#each}} and {{/each}}). Helper iterates over the array and evaluate the template for each item. Concatenated result is returned.

So, you don't have to use this.

<ul>
{{#each array}}
  <li>{{string}}</li>
{{/each}}    
</ul>

Fiddle Example

Ledorub
  • 354
  • 3
  • 9
0

Try this code

<ul>
{{#each array}}
<li>{{this.string}}</li>
{{/each}}    
</ul>
Mohammad Akbari
  • 4,486
  • 6
  • 43
  • 74