Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to print subdocument value in html #4567

Closed
Gajendrasinh opened this issue Sep 27, 2016 · 3 comments
Closed

How to print subdocument value in html #4567

Gajendrasinh opened this issue Sep 27, 2016 · 3 comments
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary

Comments

@Gajendrasinh
Copy link

When i call this router i got below data

app.get('/contacts/list', function(req, res){
db.collection('contacts').find().toArray((err, result) => {
if (err) return console.log(err)
//console.log(JSON.stringify(result) );
res.render('ListContact.html', {page_title:"All Contacts", contact: result})
db.close();
// console.log(result);
})
});

Collection DATA

{
"_id" : ObjectId("57ea35b6d085c304201490a7"),
"name" : "k",
"mobile" : "k",
"email" : "k@gmail.com",
"company" : "k",
"designation" : "k",
"information" : [
{
"owner" : "k",
"website" : "k",
"phone" : "k",
"otherPhone" : "k",
"skype" : "k",
"LinkedIn" : null,
"facebook" : "k",
"Twitter" : "k",
"google" : "k",
"currency" : "k"
}
],
"BillingAddress" : [
{
"addressline1" : "k",
"addressline2" : "k",
"city" : "k",
"zipcode" : "k",
"state" : "k",
"country" : "k"
}
],
"Details" : [
{
"description" : "k",
"tags" : "k"
}
]
}

i want to display this value in html

  <table class="table">
    <thead>
       <tr>
        <th width="50px">No</th>
        <th>Name</th>
        <th>Designation</th>
        <th>Company</th>
        <th>Email</th>
        <th>Mobile</th>
        <th>Owner</th>
        <th>Tags</th>
      </tr>
    </thead>
    </thead>
    <tbody>
         <% if(contact.length){ 

         for(var i = 0;i < contact.length;i++) { %>

         <tr>
          <td><%=(i+1)%></td>
          <td><%=contact[i].name%></td>
          <td><%=contact[i].designation%></td>
          <td><%=contact[i].company%></td>
          <td><%=contact[i].email%></td>
          <td><%=contact[i].mobile%></td>
          <td><%=contact[i].owner%></td>
          <td><%=contact[i].tags%></td>
        </tr>
        <% }

      }else{ %>
      <tr>
        <td colspan="3">No Contact in list</td>
      </tr>
      <% } %>

      </tbody>
  </table>

when run not display owner value

@Gajendrasinh
Copy link
Author

How can i print that?

Best Regards,
Gajendrasinh Zala

On Fri, Sep 30, 2016 at 3:15 AM, Varun Jayaraman notifications@github.com
wrote:

Your owner value lives on an object within the information array, it
doesn't live directly on contact


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#4567 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJ8rlFY-OhqZHZM_Km-KufPhOLFRsOraks5qvDGIgaJpZM4KHj1g
.

@vkarpov15
Copy link
Collaborator

vkarpov15 commented Oct 1, 2016

Doesn't look like there's an owner property in your data. Perhaps you want to use contact: result.infortmation ?

@vkarpov15 vkarpov15 added the help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary label Oct 1, 2016
@sobafuchs
Copy link
Contributor

Closing this since this just an issue of improperly accessing properties on the objects that live in the information array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Projects
None yet
Development

No branches or pull requests

3 participants