在流星空间键模板中按索引返回数组项

时间:2022-06-13 17:27:31

I want to access the first item of an array inside a meteor template, I'm using this syntax :

我想访问流星模板中的数组的第一项,我正在使用这种语法:

<p>{{array[0]}}</p>

However it doesn't seem like it's working. I don't want to iterate through values using {{#each}}, just pick the first one from the array.

然而,它似乎并没有起作用。我不想使用{{#each}}迭代值,只需从数组中选择第一个。

1 个解决方案

#1


14  

This is just a problem of syntax, the correct one is the following :

这只是语法问题,正确的如下:

<p>{{array.[0]}}</p>

Notice the . dot between the array property and the brackets (array indexing) notation ?

请注意。数组属性和括号(数组索引)表示法之间的点?

Here is the (hidden) docs for this :

这是(隐藏的)文档:

https://github.com/meteor/meteor/wiki/Using-Blaze#dotted-helpers-with-numeric-indices

https://github.com/meteor/meteor/wiki/Using-Blaze#dotted-helpers-with-numeric-indices

#1


14  

This is just a problem of syntax, the correct one is the following :

这只是语法问题,正确的如下:

<p>{{array.[0]}}</p>

Notice the . dot between the array property and the brackets (array indexing) notation ?

请注意。数组属性和括号(数组索引)表示法之间的点?

Here is the (hidden) docs for this :

这是(隐藏的)文档:

https://github.com/meteor/meteor/wiki/Using-Blaze#dotted-helpers-with-numeric-indices

https://github.com/meteor/meteor/wiki/Using-Blaze#dotted-helpers-with-numeric-indices