如何在流星模板中访问数组的X项?
感谢Return array item by index in a meteor spacebars template我知道如何为特定索引执行此操作:
<p>{{array.[0]}}</p>
但我的问题是如何为运行时定义的索引做到这一点。假设X已定义且具有有效值。为什么这对我不起作用?
<p>{{array.[X]}}</p>
你可以试试
<p>{{array.[index]}}</p>
例如。 <p>{{array.[0]}}</p>
要么
{{#each getArray}}
<div class="item" data-value="{{someHelper @index}}">
{{this}}
</div>
{{/each}}
同样的问题,
我结束使用一般助手,{{arrayIndex array index}}
很简单
import { Template } from 'meteor/templating'
Template.registerHelper('arrayIndex', function (array, index) {
return array[index]
})