handlebars: how to access an array?

2019-06-26 00:57发布

I have the following simplified document:

{
    channel:'Channelname',
    users: [
        {userId:1},
        {userId:2},
        {userId:3}
    ]
}

How can i access the userId's in a {{#each}} loop like so:

{{#each channels}}
    {{channel}}
    {{#each channels.users}}
        {{userId}} //or {{channels.users.userId}} ?
    {{/each}}
{{/each}}

The first {{#each}} loop prints my channelname as expected, but the second {{#each}} loop doesn't print anything.

Regards, Cid

1条回答
看我几分像从前
2楼-- · 2019-06-26 01:33

Use

{{#each channels}}
    {{channel}}
    {{#each users}}
        {{userId}}
    {{/each}}
{{/each}}

When going into an each loop, handlebars will use the key names in the array directly.

查看更多
登录 后发表回答