如何通过句柄中的索引访问访问数组项目? [英] How do I access an access array item by index in handlebars?

查看:122
本文介绍了如何通过句柄中的索引访问访问数组项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  {
我试图指定一个数组中某个项目的索引人们:[
{name:Yehuda Katz},
{name:Luke},
{name:Naomi}
]
}

使用这个:

 < ul id =luke_should_be_here> 
{{people [1] .name}}
< / ul>

如果上述不可行,我将如何编写一个可以访问数组?

解决方案

试试这个:

 < ul id =luke_should_be_here> 
{{people.1.name}}
< / ul>


I am trying to specify the index of an item in an array within a handlebars template:

{
  people: [
    {"name":"Yehuda Katz"},
    {"name":"Luke"},
    {"name":"Naomi"}
  ]
}

using this:

<ul id="luke_should_be_here">
{{people[1].name}}
</ul>

If the above is not possible, how would I write a helper that could access a spefic item within the array?

解决方案

Try this:

<ul id="luke_should_be_here">
{{people.1.name}}
</ul>

这篇关于如何通过句柄中的索引访问访问数组项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆