Chromos
Chromos

Reputation: 1921

Meteor accounts-list

I want to display all registered accounts in my meteor app. I published and subscibed to the Meteor.users collection and build a template to show email-addresses. The problem is I don't understand how I should navigate the data.

<template name="contacts">
<br>
<ul class="list-group">
    {{#each users}}
      <li class="list-group-item">
        <span class="badge">14</span>
        {{emails}}
      </li>
    {{/each}}
</ul>
</template>

{{emails}} is an array with json-objects and I don't know how to handle it to get the "address" field displayed.

This is my JS:

Template.kontakte.users = function (){
   return Meteor.users.find();
}

Upvotes: 0

Views: 90

Answers (1)

chaosbohne
chaosbohne

Reputation: 2474

First create a subtemplate, looks better:

<template name="contacts">
   <ul class="list-group">
    {{#each users}}
      {{> user}}
    {{/each}}
  </ul>
</template>


<template name="user">
  <li class="list-group-item">
    <span class="badge">14</span>
    {{email}}
  </li>
</template>

In template user the userObject is available via this pointer. The email can be shown with helper functions.

Template.user.helpers({
  email: function() {
    return this.emails[0].address;
  }
});

Note, this just shows the first email in your array.

Upvotes: 2

Related Questions