S
S
semolex2014-11-14 18:39:46
MongoDB
semolex, 2014-11-14 18:39:46

How to render nested objects from MongoDB with Backbone\Underscore?

Such a question:
Flask + MongoDB is used on the backend. For one of the URLs, I return a collection of objects that contain links to other objects.
As a result, when I try to render objects in the template in this way:

<% _.each(users.toArray(), function(user, key, list) { %>
  
     <tr>
       <td><%- user.get('first_name') %></td>
       <td><%- user.get('last_name') %></td>
       <td><%- user.get('login') %></td>
       <td><%- user.get('email') %></td>
       <td><%- user.get('books') %></td>
       <td><%- user.get('friends') %></td>  
</tr>     
<% }) %>

Then instead of books , I render [object Object], that is, the type of the object and not its attributes. How do I access the books attributes?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Kitmanov, 2014-11-14
@semolex

user.get('books').property

O
overmes, 2014-11-14
@overmes

nothing is clear
, try in the debugger to see what you have there and with the help of watch to see what you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question