Meteor flame selects a specific element by array index

Is there a way to access the index of the array inside each auxiliary block in the meteor shower?

I am looking for something like this.

{{#each myarray}} {{this.arrayIndex3}} {{/each}} 
+5
source share
1 answer

I'm afraid there is no standard way to do this yet, however you can write a helper that maps your array to a list of index / value pairs and iterates over it to display what you want.

Js

 Template.myTemplate.helpers({ myArrayWithIndex: function(){ return _.map(this.myArray,function(value,index){ return { index:index, value:value }; }); } }); 

HTML

 <template name="myTemplate"> {{#each myArrayWithIndex}} myArray[{{index}}] == {{value}} {{/each}} </template> 

You can also define your own helper block called {{#eachWithIndex}} that automates this process.

+1
source

Source: https://habr.com/ru/post/1204762/


All Articles