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