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
Post a Comment