[[+content_image]]
Y
Y
Yan Vetrov2019-03-28 12:58:37
Handlebars
Yan Vetrov, 2019-03-28 12:58:37

How to get elements of nested arrays in handlebars?

There is data:

var birthday = {
    day: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],
    month: [[1, 'Января'], [2, 'Февраля'], [3, 'Марта'], [4, 'Апреля'], [5, 'Мая'], [6, 'Июня'], [7, 'Июля'], [8, 'Августа'], [9, 'Сентября'], [10, 'Октября'], [11, 'Ноября'], [12, 'Декабря']]
}

I need to insert the second elements of nested month arrays into the handlebars template (that is, the month itself, without its index).
Here is my template:
{{#each month}}
           {{#each this}}
                     <option>{{@index}} {{this}}</option>
           {{/each}}
{{/each}}

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
0
0xD34F, 2019-03-28
@id_pripyat

{{#each month}}
  <option>{{@index}} {{this.[1]}}</option>
{{/each}}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question