javascript - How can I access a variable-referenced array element in Meteor spacebars? -


in spacebars template, have javascript array x , index i, eg.

template.test.helpers({     'foo': function() {         return {             x: ['aa','bb','cc'],             i: 1         }     } }); 

i can access fixed elements of x in template {{ x.[1] }}:

{{template name="test"}}     {{#with foo}}         {{x.[1]}}     {{/with}} {{/template}} 

but {{ x.[i] }} doesn't work.

how can access x[i]? thanks!

one solution define custom helper:

template.test.helpers({     'getelement': function(a, i) {         return a[i];     } }); 

and in template, use:

{{ getelement x }} 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -