Nazar
Nazar

Reputation: 182

meteor templates object with array

I'm new in meteor templates and trying to render emails from the next user objects with emails array:

{
  "_id" : "8ngggLthJ6NRKJRfG",
  "emails" : [
    {
        "address" : "[email protected]",
        "verified" : false
    }
  ]
}

Template helper:

Template.user.helpers({
  users() {
    return Meteor.users.find({}, { sort: { createdAt: -1 } }).fetch();
  },
});

Template:

<template name="chats">
  <ul>
   {{#each users}}
     {{> user}}
   {{/each}}
 </ul>
</template>


<template name="user">
  <li>{{emails[0].address}}</li>
</template>

but I get error: "Error: Can't call non-function: [object Object]"

How can I fix it? Thanks in advance.

Upvotes: 0

Views: 92

Answers (1)

Ankur Soni
Ankur Soni

Reputation: 6018

emails is an array, so kindly use emails.[0].address

Upvotes: 1

Related Questions