I
I
Ilya Suhodolskiy2015-03-28 23:41:04
Node.js
Ilya Suhodolskiy, 2015-03-28 23:41:04

EJS-locals. How to withdraw?

Users.find({}).populate('_group').exec(callback);

EJS: 
<% users.forEach(function(user) { %>
     <tr>
          <td><%= user._id %></td>
          <td><%= user.email %></td>
          <td><%= user.name %></td>
          <td><%= user.photo %></td>
          <td><%= user._group  %></td>
          <td><%= user.created  %></td>
     </tr>
<% }); %>

<%= user._group %> , outputs:
{ _id: 5516d1927ec2dd3e37eb8475, name: 'Администратор' }

How to display only the name of the group "name"?
<%= user._group.name %> - undefined

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2015-03-29
@standy

Try this: user.toObject()._group.name
the toObject method returns a pure javascript object, without such features

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question